Skip to content

Commit

Permalink
cran: change static cachedir to function cachedir()
Browse files Browse the repository at this point in the history
  • Loading branch information
japhir committed Apr 12, 2024
1 parent 75e26db commit ca868ac
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
14 changes: 7 additions & 7 deletions R/get_solution.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#'
#' # ignore the below, this is just to make CRAN builds happy!
#' # remove the directory with the cached astronomical solution to clean up
#' unlink(snvecR:::cachedir, recursive = TRUE)
#' unlink(snvecR:::cachedir(), recursive = TRUE)
#' }
#' @export
get_solution <- function(astronomical_solution = "full-ZB18a", quiet = FALSE, force = FALSE) {
Expand Down Expand Up @@ -153,9 +153,9 @@ get_ZB <- function(astronomical_solution = "full-ZB18a",
}

# where will we save our cached results?
raw_path <- paste0(cachedir, "/", astronomical_solution, ".dat")
csv_path <- paste0(cachedir, "/", astronomical_solution, ".csv")
rds_path <- paste0(cachedir, "/", astronomical_solution, ".rds")
raw_path <- paste0(cachedir(), "/", astronomical_solution, ".dat")
csv_path <- paste0(cachedir(), "/", astronomical_solution, ".csv")
rds_path <- paste0(cachedir(), "/", astronomical_solution, ".rds")

# read final processed file from cache if available
if (!force && file.exists(rds_path)) {
Expand Down Expand Up @@ -242,12 +242,12 @@ get_ZB <- function(astronomical_solution = "full-ZB18a",
if (!save_cache) {
return(raw)
} else {
if (!dir.exists(cachedir)) {
dir.create(cachedir, recursive = TRUE, showWarnings = TRUE)
if (!dir.exists(cachedir())) {
dir.create(cachedir(), recursive = TRUE, showWarnings = TRUE)
}
if (!quiet) {
cli::cli_alert_info(
"The cache directory is {.file {cachedir}}."
"The cache directory is {.file {cachedir()}}."
)
}

Expand Down
4 changes: 3 additions & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
VER <- glue::glue("snvecR VERSION: {packageVersion('snvecR')} {if(!is.na(packageDate('snvecR'))) packageDate('snvecR') else Sys.Date()}")

cachedir <- R_user_dir("snvecR", which = "cache")
cachedir <- function() {
R_user_dir("snvecR", which = "cache")
}

AU <- 1.49597870700e11 # m
GM <- 1.32712440041e20 # m3/s2
Expand Down
2 changes: 1 addition & 1 deletion R/snvec.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
#'
#' # ignore the below, this is just to make CRAN builds happy!
#' # remove the directory with the cached astronomical solution to clean up
#' unlink(snvecR:::cachedir, recursive = TRUE)
#' unlink(snvecR:::cachedir(), recursive = TRUE)
#' }
#' @export
snvec <- function(tend = -1e3,
Expand Down
2 changes: 1 addition & 1 deletion man/get_solution.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/snvec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cleanup <- function() {
# get cachedir from globals.R
## cachedir <- R_user_dir("snvecR", which = "cache")
if (dir.exists(cachedir) && !interactive()) {
if (dir.exists(cachedir()) && !interactive()) {
cli::cli_inform(
"Removing {.file {cachedir}} from reproducible environment."
"Removing {.file {cachedir()}} from reproducible environment."
)
unlink(cachedir, recursive = TRUE)
unlink(cachedir(), recursive = TRUE)
}
}

Expand Down
2 changes: 1 addition & 1 deletion vignettes/analyze_grid_td-ed.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,5 @@ Wickham, H., Çetinkaya-Rundel, M., & Grolemund, G. (2023). R for Data Science:
```{r teardown, include = FALSE}
# ignore the below, this is just to make CRAN builds happy!
# remove the directory with the cached astronomical solution to clean up
unlink(snvecR:::cachedir, recursive = TRUE)
unlink(snvecR:::cachedir(), recursive = TRUE)
```

0 comments on commit ca868ac

Please sign in to comment.