@@ -84,22 +84,47 @@ cache_size <- function(board) {
84
84
85
85
is.board <- function (x ) inherits(x , " pins_board" )
86
86
87
- # ' Retrieve Default Cache Path
87
+ # ' Retrieve default cache path
88
88
# '
89
89
# ' Retrieves the default path used to cache boards and pins. Makes
90
- # ' use of the `rappdirs` package to use cache folders
91
- # ' defined by each OS.
90
+ # ' use of [rappdirs::user_cache_dir()] for cache folders defined by each OS.
91
+ # ' Remember that you can set the cache location for an individual board object
92
+ # ' via the `cache` argument.
92
93
# '
93
94
# ' @param name Board name
94
- # ' @keywords internal
95
+ # ' @details
96
+ # ' There are several environment variables available to control the location of
97
+ # ' the default pins cache:
98
+ # '
99
+ # ' - Use `PINS_CACHE_DIR` to set the cache path for _only_ pins functions
100
+ # ' - Use `R_USER_CACHE_DIR` to set the cache path for all functions that use rappdirs
101
+ # '
102
+ # ' On system like AWS Lambda that is read only (for example, only `/tmp` is
103
+ # ' writeable), set either of these to [base::tempdir()]. You may also need to
104
+ # ' set environment variables like `HOME` and/or `R_USER_DATA_DIR` to the
105
+ # ' session temporary directory.
106
+ # '
95
107
# ' @examples
96
108
# ' # retrieve default cache path
97
109
# ' board_cache_path("local")
110
+ # '
111
+ # ' # set with env vars:
112
+ # ' withr::with_envvar(
113
+ # ' c("PINS_CACHE_DIR" = "/path/to/cache"),
114
+ # ' board_cache_path("local")
115
+ # ' )
116
+ # ' withr::with_envvar(
117
+ # ' c("R_USER_CACHE_DIR" = "/path/to/cache"),
118
+ # ' board_cache_path("local")
119
+ # ' )
120
+ # '
98
121
# ' @export
99
122
board_cache_path <- function (name ) {
100
123
# R_CONFIG_ACTIVE suggests we're in a production environment
101
124
if (has_envvars(" R_CONFIG_ACTIVE" ) || has_envvars(" PINS_USE_CACHE" )) {
102
- path <- tempfile()
125
+ path <- fs :: dir_create(tempdir(), " pins" )
126
+ } else if (has_envvars(" PINS_CACHE_DIR" ) ) {
127
+ path <- Sys.getenv(" PINS_CACHE_DIR" )
103
128
} else {
104
129
path <- cache_dir()
105
130
}
0 commit comments