From 1f3e72e2bcd9a518dd6c04bf17be3f6e89d75051 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 17 Nov 2022 22:00:53 +0100 Subject: [PATCH 1/5] turn verbose warning into slick messsage and move info to docs --- DESCRIPTION | 2 +- R/ui-caching.R | 27 ++++++++++++++++++++++++--- R/zzz.R | 18 ++++-------------- man/caching.Rd | 28 +++++++++++++++++++++++++--- man/combine_children.Rd | 4 ++-- tests/testthat/test-public_api.R | 4 ++-- 6 files changed, 58 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 83feabd4b..075f189d2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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: diff --git a/R/ui-caching.R b/R/ui-caching.R index 0fab7c216..ebd77ab4a 100644 --- a/R/ui-caching.R +++ b/R/ui-caching.R @@ -23,9 +23,25 @@ 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. +#' +#' @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 you loose the benefit of the cache +#' for the files not styled in the last 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()]. @@ -47,6 +63,11 @@ cache_clear <- function(cache_name = NULL, ask = TRUE) { #' which is why it takes zero space on disk (the cache is a directory with #' empty files which have the hash of output code as name). #' +#' 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 Using a cache for styler in CI/CD: #' If you want to set up caching in a CI/CD pipeline, we suggest to set the #' `{R.cache}` root path to a directory for which you have the cache enabled. diff --git a/R/zzz.R b/R/zzz.R index d0fa0b8cb..c63b44f3f 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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." )) } diff --git a/man/caching.Rd b/man/caching.Rd index 990cfa33a..30c4ac529 100644 --- a/man/caching.Rd +++ b/man/caching.Rd @@ -5,10 +5,27 @@ \title{Remember the past to be quicker in the future} \description{ Caching makes styler faster on repeated styling and is shared across all APIs -(e.g. \code{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. \code{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. } +\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 you loose the benefit of the cache +for the files not styled in the last 6 days. You can set the R option +\code{styler.cache_root} explicitly, (e.g. in your \code{.Rprofile} with +\code{\link[usethis:edit]{usethis::edit_r_profile()}}) to +\itemize{ +\item confirm the default and silence the message with +\code{options(styler.cache_root = "styler")}. +\item opt for an indefinitely long-living cache by setting the option to something +else (we recommend \code{options(styler.cache_root = "styler-perm")}, which is +also used by pre-commit). +} +} + \section{Manage the cache}{ See \code{\link[=cache_info]{cache_info()}},\code{\link[=cache_activate]{cache_activate()}} or \code{\link[=cache_clear]{cache_clear()}} for utilities to @@ -34,6 +51,11 @@ styler or a style guide you use, the cache will be re-built. The cache works by storing hashed output code as a whole and by expression, which is why it takes zero space on disk (the cache is a directory with empty files which have the hash of output code as name). + +The cache literally takes zero space on your disk, only the inode, and you +can always manually clean up with \code{\link[=cache_clear]{cache_clear()}} or just go to the +directory where the cache lives (find it with \code{\link[=cache_info]{cache_info()}}) and manually +delete files. } \section{Using a cache for styler in CI/CD}{ diff --git a/man/combine_children.Rd b/man/combine_children.Rd index fef5d4a3a..f587b9aaf 100644 --- a/man/combine_children.Rd +++ b/man/combine_children.Rd @@ -16,8 +16,8 @@ Binds two parse tables together and arranges them so that the tokens are in the correct order. } \details{ -Essentially, this is a wrapper around \code{\link[dplyr:bind]{dplyr::bind_rows()}}, but -returns \code{NULL} if the result of \code{\link[dplyr:bind]{dplyr::bind_rows()}} is a data frame with +Essentially, this is a wrapper around \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}}, but +returns \code{NULL} if the result of \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}} is a data frame with zero rows. } \keyword{internal} diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index bf5d31e42..fcae90cd4 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -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 ) }) From 43e10485056c37031cccd54fa2591b8830d2058d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 17 Nov 2022 21:15:19 +0000 Subject: [PATCH 2/5] pre-commit --- man/combine_children.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/combine_children.Rd b/man/combine_children.Rd index f587b9aaf..fef5d4a3a 100644 --- a/man/combine_children.Rd +++ b/man/combine_children.Rd @@ -16,8 +16,8 @@ Binds two parse tables together and arranges them so that the tokens are in the correct order. } \details{ -Essentially, this is a wrapper around \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}}, but -returns \code{NULL} if the result of \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}} is a data frame with +Essentially, this is a wrapper around \code{\link[dplyr:bind]{dplyr::bind_rows()}}, but +returns \code{NULL} if the result of \code{\link[dplyr:bind]{dplyr::bind_rows()}} is a data frame with zero rows. } \keyword{internal} From 52a3667b1076487b4c1bca07afb4b8fd55e2f238 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Fri, 18 Nov 2022 13:47:19 +0100 Subject: [PATCH 3/5] no mention pre-commit, different logic --- R/ui-caching.R | 16 ++++++++-------- man/caching.Rd | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/R/ui-caching.R b/R/ui-caching.R index ebd77ab4a..a1edc3247 100644 --- a/R/ui-caching.R +++ b/R/ui-caching.R @@ -31,16 +31,16 @@ cache_clear <- function(cache_name = NULL, ask = TRUE) { #' #' To comply with the CRAN policy, \{styler\} will by default clean up cache files #' that are older than 6 days. This implies that you loose the benefit of the cache -#' for the files not styled in the last 6 days. You can set the R option -#' `styler.cache_root` explicitly, (e.g. in your `.Rprofile` with -#' [usethis::edit_r_profile()]) to +#' for the files not styled in the last 6 days. #' -#' * confirm the default and silence the message with -#' `options(styler.cache_root = "styler")`. +#' If you want to avoid this, i.e., if you want the cache to last longer, you can use the +#' R option `styler.cache_root` to opt for an indefinitely long-lived cache by setting it to +#' `options(styler.cache_root = "styler-perm")`. #' -#' * 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). +#' If you are happy with the cache being cleared after 6 days, you can confirm the default and +#' silence this message by setting it instead to `options(styler.cache_root = "styler")`. +#' +#' You can make this change in your `.Rprofile` using [usethis::edit_r_profile()]). #' #' @section Manage the cache: #' See [cache_info()],[cache_activate()] or [cache_clear()] for utilities to diff --git a/man/caching.Rd b/man/caching.Rd index 30c4ac529..0870198a5 100644 --- a/man/caching.Rd +++ b/man/caching.Rd @@ -14,16 +14,16 @@ be quicker. To comply with the CRAN policy, \{styler\} will by default clean up cache files that are older than 6 days. This implies that you loose the benefit of the cache -for the files not styled in the last 6 days. You can set the R option -\code{styler.cache_root} explicitly, (e.g. in your \code{.Rprofile} with -\code{\link[usethis:edit]{usethis::edit_r_profile()}}) to -\itemize{ -\item confirm the default and silence the message with -\code{options(styler.cache_root = "styler")}. -\item opt for an indefinitely long-living cache by setting the option to something -else (we recommend \code{options(styler.cache_root = "styler-perm")}, which is -also used by pre-commit). -} +for the files not styled in the last 6 days. + +If you want to avoid this, i.e., if you want the cache to last longer, you can use the +R option \code{styler.cache_root} to opt for an indefinitely long-lived cache by setting it to +\code{options(styler.cache_root = "styler-perm")}. + +If you are happy with the cache being cleared after 6 days, you can confirm the default and +silence this message by setting it instead to \code{options(styler.cache_root = "styler")}. + +You can make this change in your \code{.Rprofile} using \code{\link[usethis:edit]{usethis::edit_r_profile()}}). } \section{Manage the cache}{ From 45f25e8c99551ab8fe3655d91c2eef4f2cbed90c Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sat, 19 Nov 2022 12:18:23 +0100 Subject: [PATCH 4/5] don't need {usethis} --- R/ui-caching.R | 2 +- man/caching.Rd | 2 +- man/combine_children.Rd | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/ui-caching.R b/R/ui-caching.R index a1edc3247..3af34bec4 100644 --- a/R/ui-caching.R +++ b/R/ui-caching.R @@ -40,7 +40,7 @@ cache_clear <- function(cache_name = NULL, ask = TRUE) { #' If you are happy with the cache being cleared after 6 days, you can confirm the default and #' silence this message by setting it instead to `options(styler.cache_root = "styler")`. #' -#' You can make this change in your `.Rprofile` using [usethis::edit_r_profile()]). +#' You can make this change in your `.Rprofile` using `usethis::edit_r_profile()`. #' #' @section Manage the cache: #' See [cache_info()],[cache_activate()] or [cache_clear()] for utilities to diff --git a/man/caching.Rd b/man/caching.Rd index 0870198a5..5c87ac05b 100644 --- a/man/caching.Rd +++ b/man/caching.Rd @@ -23,7 +23,7 @@ R option \code{styler.cache_root} to opt for an indefinitely long-lived cache by If you are happy with the cache being cleared after 6 days, you can confirm the default and silence this message by setting it instead to \code{options(styler.cache_root = "styler")}. -You can make this change in your \code{.Rprofile} using \code{\link[usethis:edit]{usethis::edit_r_profile()}}). +You can make this change in your \code{.Rprofile} using \verb{usethis::edit_r_profile()]}. } \section{Manage the cache}{ diff --git a/man/combine_children.Rd b/man/combine_children.Rd index fef5d4a3a..f587b9aaf 100644 --- a/man/combine_children.Rd +++ b/man/combine_children.Rd @@ -16,8 +16,8 @@ Binds two parse tables together and arranges them so that the tokens are in the correct order. } \details{ -Essentially, this is a wrapper around \code{\link[dplyr:bind]{dplyr::bind_rows()}}, but -returns \code{NULL} if the result of \code{\link[dplyr:bind]{dplyr::bind_rows()}} is a data frame with +Essentially, this is a wrapper around \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}}, but +returns \code{NULL} if the result of \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}} is a data frame with zero rows. } \keyword{internal} From b74067c626e37e60990bb2c5298bec341039fc4e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 19 Nov 2022 11:31:03 +0000 Subject: [PATCH 5/5] pre-commit --- man/caching.Rd | 2 +- man/combine_children.Rd | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/man/caching.Rd b/man/caching.Rd index 5c87ac05b..59a7db6cb 100644 --- a/man/caching.Rd +++ b/man/caching.Rd @@ -23,7 +23,7 @@ R option \code{styler.cache_root} to opt for an indefinitely long-lived cache by If you are happy with the cache being cleared after 6 days, you can confirm the default and silence this message by setting it instead to \code{options(styler.cache_root = "styler")}. -You can make this change in your \code{.Rprofile} using \verb{usethis::edit_r_profile()]}. +You can make this change in your \code{.Rprofile} using \code{usethis::edit_r_profile()}. } \section{Manage the cache}{ diff --git a/man/combine_children.Rd b/man/combine_children.Rd index f587b9aaf..fef5d4a3a 100644 --- a/man/combine_children.Rd +++ b/man/combine_children.Rd @@ -16,8 +16,8 @@ Binds two parse tables together and arranges them so that the tokens are in the correct order. } \details{ -Essentially, this is a wrapper around \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}}, but -returns \code{NULL} if the result of \code{\link[dplyr:bind_rows]{dplyr::bind_rows()}} is a data frame with +Essentially, this is a wrapper around \code{\link[dplyr:bind]{dplyr::bind_rows()}}, but +returns \code{NULL} if the result of \code{\link[dplyr:bind]{dplyr::bind_rows()}} is a data frame with zero rows. } \keyword{internal}