Skip to content

Commit ec05d3e

Browse files
authored
Add new PINS_CACHE_PATH env var, plus documentation (#748)
* New `PINS_CACHE_PATH` plus documentation * Update NEWS * Feedback from code review
1 parent 4775ec7 commit ec05d3e

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# pins (development version)
22

3+
* New environment variable `PINS_CACHE_DIR` controls the location of the
4+
default cache path (#748).
5+
36
# pins 1.2.0
47

58
## Breaking changes

R/board.R

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,47 @@ cache_size <- function(board) {
8484

8585
is.board <- function(x) inherits(x, "pins_board")
8686

87-
#' Retrieve Default Cache Path
87+
#' Retrieve default cache path
8888
#'
8989
#' 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.
9293
#'
9394
#' @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+
#'
95107
#' @examples
96108
#' # retrieve default cache path
97109
#' 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+
#'
98121
#' @export
99122
board_cache_path <- function(name) {
100123
# R_CONFIG_ACTIVE suggests we're in a production environment
101124
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")
103128
} else {
104129
path <- cache_dir()
105130
}

_pkgdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ reference:
4747
- title: Other functions
4848
contents:
4949
- cache_browse
50+
- board_cache_path
5051
- write_board_manifest
5152

5253
- title: Legacy API

man/board_cache_path.Rd

Lines changed: 28 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)