Skip to content

Commit 7332ac5

Browse files
make R.cache an import
This remove one step in the styler setup for caching. Now, the only thing an interactive user has to do is to allow R.cache to set up a permanent cache. I believe this is worth the three extra recursive dependencies because there is actually no reason why you are strictly against using caching, even on CI/CD it will speed up things.
1 parent 8d856a5 commit 7332ac5

File tree

11 files changed

+24
-144
lines changed

11 files changed

+24
-144
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ matrix:
3838
- r: release
3939
env:
4040
- BUILD_PKGDOWN: true
41-
- r: release
42-
env:
43-
- R_REMOVE_RCACHE: true
4441
- r: devel
4542

4643
#env

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Imports:
2121
cli (>= 1.1.0),
2222
magrittr (>= 1.0.1),
2323
purrr (>= 0.2.3),
24+
R.cache (>= 0.14.0),
2425
rematch2 (>= 2.0.1),
2526
rlang (>= 0.1.1),
2627
rprojroot (>= 1.1),
@@ -35,7 +36,6 @@ Suggests:
3536
here,
3637
knitr,
3738
prettycode,
38-
R.cache (>= 0.14.0),
3939
rmarkdown,
4040
rstudioapi (>= 0.7),
4141
testthat (>= 2.1.0)

R/communicate.R

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,3 @@ assert_data.tree_installation <- function() {
3434
abort("The package data.tree needs to be installed for this functionality.")
3535
}
3636
}
37-
38-
#' Assert the R.cache installation in conjunction with the cache config
39-
#'
40-
#' R.cache needs to be installed if caching functionality is enabled
41-
#' @keywords internal
42-
assert_R.cache_installation <- function(action = "abort") {
43-
# fail if R.cache is not installed but feature is actiavted.
44-
if (!rlang::is_installed("R.cache")) {
45-
msg_basic <- paste(
46-
"R package R.cache is not installed, which is needed when the caching ",
47-
"feature is activated. Please install the package with ",
48-
"`install.packages('R.cache')` and then restart R to enable the ",
49-
"caching feature of styler or permanently deactivate the feature by ",
50-
"adding `styler::cache_deactivate()` to your .Rprofile, e.g. via ",
51-
"`usethis::edit_r_profile()`.",
52-
sep = ""
53-
)
54-
55-
if (action == "abort") {
56-
rlang::abort(msg_basic)
57-
} else {
58-
rlang::warn(paste0(
59-
msg_basic, " ",
60-
"Deactivating the caching feature for the current session."
61-
))
62-
cache_deactivate(verbose = FALSE)
63-
}
64-
}
65-
}

R/transform-files.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ make_transformer <- function(transformers,
7878
warn_empty = TRUE) {
7979
force(transformers)
8080
assert_transformers(transformers)
81-
if (cache_is_activated()) assert_R.cache_installation(action = "warn")
8281

8382
function(text) {
84-
should_use_cache <- cache_is_activated() && rlang::is_installed("R.cache")
83+
should_use_cache <- cache_is_activated()
8584

8685
if (should_use_cache) {
8786
use_cache <- is_cached(text, transformers)

R/ui-caching.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#' @family cache managers
1515
#' @export
1616
cache_clear <- function(cache_name = NULL, ask = TRUE) {
17-
assert_R.cache_installation()
1817
path_cache <- cache_find_path(cache_name)
1918
R.cache::clearCache(path_cache, prompt = ask)
2019
cache_deactivate(verbose = FALSE)
@@ -26,20 +25,23 @@ cache_clear <- function(cache_name = NULL, ask = TRUE) {
2625
#' Caching makes styler faster on repeated styling. It does not cache input
2726
#' but output code. That means if you style code that already complies to a
2827
#' style guide and you have previously styled that code, it will be quicker.
29-
#' Code is cached by expression and the cache is shared across all APIs.
28+
#' Code is cached by expression and the cache is shared across all APIs (e.g.
29+
#' `style_text()` and Addin.
3030
#'
3131
#' @section Setup:
32-
#' styler by default uses caching. It may prompt you to install the R package
33-
#' `R.cache` the first time you want to use it. R.cache will also ask you to let
34-
#' it create a permanent cache on your file system that styler will use.
32+
#' styler by default uses caching, via the `{R.cache}` package. You will be
33+
#' asked you to let it create a permanent cache on your file system that styler
34+
#' will use in case you have not set that up already for another tool that
35+
#' uses `{R.cache}`.
3536
#' This is needed if you want to cache across R sessions and not just within.
3637
#'
3738
#' @section Non-interactive use:
3839
#' Note that if you have never authorized `{R.cache}` to create the cache in a
3940
#' permenent directory, it wil build the cache in a temporary directory. To
4041
#' create a permenent cache, just open an interactive R session and type
4142
#' `cache_info()`. You can see under `Location:` if a permanent directory is
42-
#' used and if not, `{R.cache}` will ask you to create one.
43+
#' used and if not, `{R.cache}` will ask you to create one the first time you
44+
#' use `{R.cache}` in an R session.
4345
#'
4446
#' @section Invalidation:
4547
#' The cache is specific to a version of styler by default, because different
@@ -77,7 +79,6 @@ NULL
7779
#' @family cache managers
7880
#' @export
7981
cache_info <- function(cache_name = NULL, format = "both") {
80-
assert_R.cache_installation()
8182
rlang::arg_match(format, c("tabular", "lucid", "both"))
8283
path_cache <- cache_find_path(cache_name)
8384
files <- list.files(path_cache, full.names = TRUE)
@@ -119,7 +120,6 @@ cache_info <- function(cache_name = NULL, format = "both") {
119120
#' @family cache managers
120121
#' @export
121122
cache_activate <- function(cache_name = NULL, verbose = TRUE) {
122-
assert_R.cache_installation()
123123
if (!is.null(cache_name)) {
124124
options("styler.cache_name" = cache_name)
125125
} else {

man/assert_R.cache_installation.Rd

Lines changed: 0 additions & 12 deletions
This file was deleted.

man/caching.Rd

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

tests/testthat/test-cache-high-level-api.R

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
capture.output(test_that("activated cache brings speedup on style_file() API", {
2-
skip_if_not_installed("R.cache")
32
on.exit(clear_testthat_cache())
43
clear_testthat_cache()
54
activate_testthat_cache()
@@ -25,7 +24,7 @@ text <- c(
2524
rep(10)
2625

2726
capture.output(test_that("activated cache brings speedup on style_text() API on character vector", {
28-
skip_if_not_installed("R.cache")
27+
2928
activate_testthat_cache()
3029
on.exit(clear_testthat_cache())
3130
clear_testthat_cache()
@@ -37,7 +36,7 @@ capture.output(test_that("activated cache brings speedup on style_text() API on
3736
}))
3837

3938
capture.output(test_that("activated cache brings speedup on style_text() API on character scalar", {
40-
skip_if_not_installed("R.cache")
39+
4140
activate_testthat_cache()
4241
on.exit(clear_testthat_cache())
4342
clear_testthat_cache()
@@ -50,7 +49,7 @@ capture.output(test_that("activated cache brings speedup on style_text() API on
5049

5150

5251
capture.output(test_that("no speedup when tranformer changes", {
53-
skip_if_not_installed("R.cache")
52+
5453
activate_testthat_cache()
5554
on.exit(clear_testthat_cache())
5655
clear_testthat_cache()
@@ -68,7 +67,6 @@ capture.output(
6867
"activated cache brings speedup on style_text() API on ",
6968
"character scalar and character vector (mixed)"
7069
), {
71-
skip_if_not_installed("R.cache")
7270
activate_testthat_cache()
7371
on.exit(clear_testthat_cache())
7472
clear_testthat_cache()
@@ -81,7 +79,7 @@ capture.output(
8179

8280

8381
capture.output(test_that("unactivated cache does not bring speedup", {
84-
skip_if_not_installed("R.cache")
82+
8583
on.exit(clear_testthat_cache())
8684
clear_testthat_cache()
8785
cache_deactivate()
@@ -93,7 +91,6 @@ capture.output(test_that("unactivated cache does not bring speedup", {
9391

9492
capture.output(test_that("avoid deleting comments #584 (see commit messages)", {
9593

96-
skip_if_not_installed("R.cache")
9794
on.exit(clear_testthat_cache())
9895
clear_testthat_cache()
9996
activate_testthat_cache()
@@ -119,7 +116,6 @@ capture.output(test_that("avoid deleting comments #584 (see commit messages)", {
119116

120117
capture.output(test_that("avoid removing roxygen mask (see commit messages in #584)", {
121118

122-
skip_if_not_installed("R.cache")
123119
on.exit(clear_testthat_cache())
124120
clear_testthat_cache()
125121
activate_testthat_cache()

tests/testthat/test-cache-with-r-cache.R

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
2-
capture.output(test_that("No warnings are issued when R.cache is installed", {
3-
skip_if_not_installed("R.cache")
4-
on.exit(clear_testthat_cache())
5-
expect_silent(assert_R.cache_installation())
6-
expect_warning(style_text("1+1"), NA)
7-
expect_warning(activate_testthat_cache(), NA)
8-
expect_warning(style_text("1+1"), NA)
9-
expect_silent(assert_R.cache_installation())
10-
}))
11-
12-
capture.output(test_that("Cache management works when R.cache is installed", {
13-
skip_if_not_installed("R.cache")
1+
capture.output(test_that("Cache management works", {
142
on.exit(clear_testthat_cache())
153
clear_testthat_cache()
164
# clearing a cache inactivates the caching functionality.
175
expect_false(cache_info(format = "tabular")$activated)
186
activate_testthat_cache()
19-
# at fresh startup, with R.cache installed
7+
# at fresh startup
208
expect_s3_class(cache_info(format = "tabular"), "tbl_df")
219
expect_error(cache_info(), NA)
2210
expect_equal(basename(cache_activate()), styler_version)

tests/testthat/test-cache-without-r-cache.R

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)