Skip to content

Commit

Permalink
turn verbose warning into slick messsage and move info to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzwalthert committed Nov 17, 2022
1 parent 8859cc3 commit 52ed3c4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 25 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
if (rlang::is_installed("pkgapi")) "pkgapi::api_roclet" else {
warning("Please install r-lib/pkgapi to make sure the file API is kept
up to date"); NULL}))
RoxygenNote: 7.2.1
RoxygenNote: 7.2.2
Config/testthat/edition: 3
Config/testthat/parallel: true
Collate:
Expand Down
27 changes: 24 additions & 3 deletions R/ui-caching.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,30 @@ cache_clear <- function(cache_name = NULL, ask = TRUE) {
#' Remember the past to be quicker in the future
#'
#' Caching makes styler faster on repeated styling and is shared across all APIs
#' (e.g. `style_text()` and Addin).
#' That means if you style code that already complies to a
#' style guide and you have previously styled that code, it will be quicker.
#' (e.g. `style_text()` and Addin). That means if you style code that already
#' complies to a style guide and you have previously styled that code, it will
#' be quicker.
#'
#' The cache literally takes zero space on your disk, only the inode, and you
#' can always manually clean up with [cache_clear()] or just go to the
#' directory where the cache lives (find it with [cache_info()]) and manually
#' delete files.
#'
#' @section Configuring the cache:
#'
#' To comply with the CRAN policy, \{styler\} will by default clean up cache files
#' that are older than 6 days. This implies that loose the benefit of the cache
#' if a file was not styled for 6 days. You can set the R option
#' `styler.cache_root` explicitly,
#' (e.g. in your `.Rprofile` with [usethis::edit_r_profile()]) to
#'
#' * confirm the default and silence the message with
#' `options(styler.cache_root = "styler")`.
#'
#' * opt for an indefinitely long-living cache by setting the option to something
#' else (we recommend `options(styler.cache_root = "styler-perm")`, which is
#' also used by pre-commit).
#'
#' @section Manage the cache:
#' See [cache_info()],[cache_activate()] or [cache_clear()] for utilities to
#' manage the cache. You can deactivate it altogether with [cache_deactivate()].
Expand Down
18 changes: 4 additions & 14 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,11 @@ ask_to_switch_to_non_default_cache_root <- function(ask = interactive()) {
}
}


ask_to_switch_to_non_default_cache_root_impl <- function() {
rlang::warn(paste0(
"The R option `styler.cache_root` is not set, which means the cache ",
"will get cleaned up after 6 days (and repeated styling will be slower).",
" To keep cache files longer, set ",
"the option to location within the {R.cache} cache where you want to ",
"store the cache, e.g. `\"styler-perm\"`.\n\n",
"options(styler.cache_root = \"styler-perm\")\n\n",
"in your .Rprofile. Note that the cache literally ",
"takes zero space on your disk, only the inode, and you can always ",
"manually clean up with `styler::cache_clear()`, and if you update the ",
"{styler} package, the cache is removed in any case. To ignore this ",
"message in the future, set the default explictly to \"styler\" with\n\n",
"options(styler.cache_root = \"styler\")\n\nin your `.Rprofile`. This ",
"message will only be displayed once in a while.\n"
rlang::inform(paste0(
"{styler} cache is cleared after 6 days. ",
"See `?styler::caching` to configure differently or silence this message."
))
}

Expand Down
29 changes: 26 additions & 3 deletions man/caching.Rd

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

4 changes: 2 additions & 2 deletions man/combine_children.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-public_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ test_that("Can properly determine style_after_saving", {
test_that("Can display warning on unset styler cache", {
withr::local_options(styler.cache_root = NULL)
withr::local_seed(7)
expect_warning(
expect_message(
ask_to_switch_to_non_default_cache_root(ask = TRUE),
'options(styler.cache_root = "styler-perm")',
"See `?styler::caching`",
fixed = TRUE
)
})
Expand Down

0 comments on commit 52ed3c4

Please sign in to comment.