Skip to content

Commit ba35736

Browse files
emergency release to comply with CRAN policy
1 parent eac4bdf commit ba35736

File tree

3 files changed

+29
-39
lines changed

3 files changed

+29
-39
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: styler
33
Title: Non-Invasive Pretty Printing of R Code
4-
Version: 1.6.1.9000
4+
Version: 1.6.2
55
Authors@R:
66
c(person(given = "Kirill",
77
family = "Müller",

R/zzz.R

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,39 @@
1313
)
1414
toset <- !(names(op.styler) %in% names(op))
1515
if (any(toset)) options(op.styler[toset])
16-
remind_removing_old_cache()
16+
remove_cache_old_versions()
17+
remove_old_cache_files()
1718
invisible()
1819
}
1920

21+
remove_old_cache_files <- function() {
22+
all_cached <- list.files(
23+
R.cache::getCachePath(c("styler", styler_version)),
24+
full.names = TRUE
25+
)
26+
date_boundary <- Sys.time() - 60 * 60 * 24 * 6
27+
file.remove(
28+
all_cached[file.info(all_cached)$mtime < date_boundary]
29+
)
30+
}
31+
2032
#' Ask people to remove the cache
2133
#'
2234
#' The way RStudio Startup works does not allow o read the prompt for some
2335
#' reasons (https://stackoverflow.com/questions/55772436/readline-does-not-prompt-user-input-from-rprofile-site-in-rstudio)
2436
#' So we better don't use the prompt and issue a message only.
2537
#' @keywords internal
26-
remind_removing_old_cache <- function() {
27-
if (interactive() && getOption("styler.interactive_ask_remove_old_caches", TRUE)) {
28-
dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE)
29-
if (length(dirs) < 1) {
30-
return()
31-
}
32-
dirs <- dirs[unname(sapply(dirs, function(x) length(list.files(x)) > 0))]
33-
package_versions <- package_version(basename(dirs), strict = FALSE)
34-
package_versions <- package_versions[!is.na(package_versions)]
35-
old_package_versions <- package_versions[package_versions < styler_version]
36-
if (length(old_package_versions) < 1) {
37-
return()
38-
}
39-
40-
cmd <- glue::glue("styler::cache_clear(\"{basename(dirs)}\", ask = FALSE)") %>%
41-
paste0(collapse = "\n")
42-
cli::cli_alert_info(paste0(
43-
"You are using {{styler}} version {styler_version} but we found ",
44-
"caches for older versions of {{styler}}.\n",
45-
"You can delete them with the following commands:"
46-
))
47-
cat("\n")
48-
cli::cli_code(cmd)
49-
cat("\n")
50-
cli::cli_alert_info(
51-
paste(
52-
"We'll remind you every time you update {{styler}}.",
53-
"To suppress this prompt in the future:"
54-
)
55-
)
56-
cat("\n")
57-
cli::cli_code(
58-
'options("styler.interactive_ask_remove_old_caches" = FALSE)'
59-
)
38+
remove_cache_old_versions <- function() {
39+
dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE)
40+
if (length(dirs) < 1) {
41+
return()
42+
}
43+
old_package_dirs <- dirs[basename(dirs) != as.character(styler_version)]
44+
if (length(old_package_dirs) < 1) {
45+
return()
6046
}
47+
purrr::walk(old_package_dirs, function(dir) {
48+
cache_clear(basename(dir), ask = FALSE)
49+
file.remove(dir)
50+
})
6151
}

man/remind_removing_old_cache.Rd renamed to man/remove_cache_old_versions.Rd

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

0 commit comments

Comments
 (0)