Skip to content

Commit c4f79d2

Browse files
make sure that when cache is deactivated and R.cache is installed but there is no R.cache premanent directory, the user is never asked about setting up a permanent directory.
1 parent 6b4fc02 commit c4f79d2

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

R/communicate.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ assert_data.tree_installation <- function() {
3838
#' Assert the R.cache installation in conjunction with the cache config
3939
#'
4040
#' R.cache needs to be installed if caching functionality is enabled
41-
#' @param installation_only Whether or not to only check if R.cache is
42-
#' installed.
4341
#' @keywords internal
44-
assert_R.cache_installation <- function(installation_only = FALSE,
45-
action = "abort") {
42+
assert_R.cache_installation <- function(action = "abort") {
4643
# fail if R.cache is not installed but feature is actiavted.
47-
if (!rlang::is_installed("R.cache") &&
48-
ifelse(installation_only, TRUE, cache_is_activated())
49-
) {
44+
if (!rlang::is_installed("R.cache")) {
5045
msg_basic <- paste(
5146
"R package R.cache is not installed, which is needed when the caching ",
5247
"feature is activated. Please install the package with ",

R/transform-files.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,10 @@ make_transformer <- function(transformers,
7878
warn_empty = TRUE) {
7979
force(transformers)
8080
assert_transformers(transformers)
81-
assert_R.cache_installation(action = "warn")
82-
83-
is_R.cache_installed <- rlang::is_installed("R.cache")
81+
if (cache_is_activated()) assert_R.cache_installation(action = "warn")
8482

8583
function(text) {
86-
should_use_cache <- is_R.cache_installed && cache_is_activated()
84+
should_use_cache <- cache_is_activated() && rlang::is_installed("R.cache")
8785

8886
if (should_use_cache) {
8987
use_cache <- is_cached(text, transformers)

R/ui-caching.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#' @family cache managers
1515
#' @export
1616
cache_clear <- function(cache_name = NULL, ask = TRUE) {
17-
assert_R.cache_installation(installation_only = TRUE)
17+
assert_R.cache_installation()
1818
path_cache <- cache_find_path(cache_name)
1919
R.cache::clearCache(path_cache, prompt = ask)
2020
cache_deactivate(verbose = FALSE)
@@ -50,7 +50,7 @@ NULL
5050
#' @family cache managers
5151
#' @export
5252
cache_info <- function(cache_name = NULL, format = "both") {
53-
assert_R.cache_installation(installation_only = TRUE)
53+
assert_R.cache_installation()
5454
rlang::arg_match(format, c("tabular", "lucid", "both"))
5555
path_cache <- cache_find_path(cache_name)
5656
files <- list.files(path_cache, full.names = TRUE)
@@ -92,7 +92,7 @@ cache_info <- function(cache_name = NULL, format = "both") {
9292
#' @family cache managers
9393
#' @export
9494
cache_activate <- function(cache_name = NULL, verbose = TRUE) {
95-
assert_R.cache_installation(installation_only = TRUE)
95+
assert_R.cache_installation()
9696
if (!is.null(cache_name)) {
9797
options("styler.cache_name" = cache_name)
9898
} else {

man/assert_R.cache_installation.Rd

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

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,46 @@ test_that("Cache management fails mostly when R.cache is not installed", {
44
expect_error(activate_testthat_cache(), "is needed when the caching feature is activated")
55
expect_error(cache_clear("testthat"), "is needed when the caching feature is activated")
66
expect_error(capture.output(cache_deactivate()), NA)
7-
expect_silent(assert_R.cache_installation())
87
expect_error(
9-
assert_R.cache_installation(installation_only = TRUE),
8+
assert_R.cache_installation(),
109
"is needed when the caching feature is activated"
1110
)
1211
})
1312

1413

1514
test_that("styling works when R.cache is not installed", {
1615
skip_if(rlang::is_installed("R.cache"))
16+
# no warning when cache is disabled manually
17+
expect_output(
18+
withr::with_options(
19+
# simulate .onLoad() in fresh R session
20+
list(styler.cache_name = styler_version),
21+
{
22+
cache_deactivate()
23+
style_text("1+1")
24+
}
25+
),
26+
"Deactivated cache."
27+
)
28+
29+
# warning if cache is not disabled manually
1730
# warning for first time
1831
expect_warning(
1932
capture.output(
2033
withr::with_options(
2134
# simulate .onLoad() in fresh R session
22-
list(styler.cache_name = cache_derive_name()),
35+
list(styler.cache_name = styler_version),
2336
style_text("1+1")
2437
)
2538
),
26-
"Deactivating the caching feature for the current session"
39+
"R package R.cache .*Deactivating the caching feature for the current session"
2740
)
2841

2942
# No warnings subsequently
3043
expect_warning(
3144
capture.output(
3245
withr::with_options(
33-
list(styler.cache_name = cache_derive_name()), {
46+
list(styler.cache_name = styler_version), {
3447
suppressWarnings(style_text("1+1"))
3548
style_text("1+1")
3649
}

0 commit comments

Comments
 (0)