Skip to content

Commit 4ef7429

Browse files
committed
feat: make default cache directory R version
portable with rappdirs::user_cache_dir()
1 parent 1917e27 commit 4ef7429

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Imports:
3535
MMWRweek,
3636
purrr,
3737
openssl,
38+
rappdirs,
3839
readr,
3940
tibble,
4041
usethis,

R/cache.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ cache_environ$epidatr_cache <- NULL
7676
#' )
7777
#'
7878
#' @param cache_dir the directory in which the cache is stored. By default, this
79-
#' is `tools::R_user_dir()` if on R 4.0+, but must be specified for earlier
80-
#' versions of R. The path can be either relative or absolute. The
81-
#' environmental variable is `EPIDATR_CACHE_DIR`.
79+
#' is `rappdirs::user_cache_dir("R", version = "epidatr")`. The path can be
80+
#' either relative or absolute. The environmental variable is
81+
#' `EPIDATR_CACHE_DIR`.
8282
#' @param days the maximum length of time in days to keep any particular cached
8383
#' call. By default this is `1`. The environmental variable is
8484
#' `EPIDATR_CACHE_MAX_AGE_DAYS`.
@@ -103,8 +103,8 @@ set_cache <- function(cache_dir = NULL,
103103
max_size = NULL,
104104
logfile = NULL,
105105
confirm = TRUE) {
106-
if (is.null(cache_dir) && sessionInfo()$R.version$major >= 4) {
107-
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR", unset = tools::R_user_dir("epidatr"))
106+
if (is.null(cache_dir)) {
107+
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR", unset = rappdirs::user_cache_dir("R", version = "epidatr"))
108108
} else if (is.null(cache_dir)) {
109109
# earlier version, so no tools
110110
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR")

man/clear_cache.Rd

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

man/set_cache.Rd

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

0 commit comments

Comments
 (0)