Skip to content

R.cache >= 0.15.0 always uses permanent cache location #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 7 additions & 37 deletions R/cache.R
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
#' Check if the R cache is persistent
#' @keywords internal
has_persistent_R.cache <- function() {
temp_dirs <- path_if_exist(
fs::path_norm(fs::path_dir(tempdir())),
"/tmp", "/var/tmp"
)
!fs::path_has_parent(
fs::path_norm(R.cache::getCacheRootPath()), # when no cache exists, it create temp cache
temp_dirs
) %>%
any()
}

#' Issue a warning if `{R.cache}` uses temporary cache only
#'
#' This function is only exported for use in hook scripts, but it's not intended
#' to be called by the end-user directly.
#' @param temp_cache_is_enough Whether a temporary cache is accepted or not. `TRUE`
#' means no warning will be issued, `FALSE` means a warning will be issued if
#' no permanent cache is available.
#' This function used to check if a permanent cache was available and issue a
#' warning if not, but since {R.cache} version `0.15.0` (release date
#' 2021-04-27), a permanent directory will be used automatically, so this check
#' if redundant. the function is kept in the package for compatibility, i.e.
#' if someone updates the R package {precommit} but not the hook revisions.
#' @param temp_cache_is_enough ignored.
#' @family hook script helpers
#' @export
may_require_permanent_cache <- function(temp_cache_is_enough = FALSE) {
if (has_persistent_R.cache()) {
cat("Using persistent cache at", R.cache::getCacheRootPath(), "\n")
} else {
if (temp_cache_is_enough) {
cat("Using temporary cache at", R.cache::getCacheRootPath(), "\n")
} else {
cat(paste0(
"You don't have a permanent cache directory set up with {R.cache}. ",
"This means you won't get significant speedups for some hooks. ",
"Create a permanent cache in an interactive R session by \n\n1) calling ",
"`R.cache::getCachePath()` and confirm the prompt or \n\n2) ",
"non-interactively by setting the environment variable ",
"`R_CACHE_ROOTPATH` to the location you want to put the cache. \n\nYou can ",
"silent this warning with setting `args: [--no-warn-cache]` in your ",
".pre-commit-config.yaml.\n\n"
))
}
}
return()
}
12 changes: 0 additions & 12 deletions man/has_persistent_R.cache.Rd

This file was deleted.

11 changes: 6 additions & 5 deletions man/may_require_permanent_cache.Rd

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

75 changes: 0 additions & 75 deletions tests/testthat/test-cache.R

This file was deleted.

17 changes: 3 additions & 14 deletions vignettes/available-hooks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ In addition, the hook takes the following arguments that are not passed to
args: [--style_pkg=pkg.with.style.guide, --style_fun=exported.style.function]
```

* If no permanent `{R.cache}` cache exists, the hook emits a warning which you
can silence with `--no-warn-cache`.

```
id: style-files
args: [--no-warn-cache]
```
* The argument `--no-warn-cache` is ignored but allowed for compatibility.


* Argument `cache-root` is passed to `options()` to set `styler.cache_root`.
Expand Down Expand Up @@ -177,13 +171,8 @@ should pass.

A hook to run `roxygen2::roxygenize()`. Makes sure you commit your `.Rd` changes
with the source changes. To take advantage of caching, you don't need to run
`roxygen2::roxygenize()` manually anymore. If no permanent `{R.cache}` cache
exists, the hook emits a warning which you can silence with
`--no-warn-cache`.
```
id: royxgenize
args: [--no-warn-cache]
```
`roxygen2::roxygenize()` manually anymore. The option `--no-warn-cache` is
ignored but allowed for compatibility.

Because the hook will write the version of {roxygen2} to `DESCRIPTON`, you
should either make sure the version you use when you call {roxygen2}
Expand Down