From 7c64a26aeedee9923d516a750c2a693242bc47ae Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Mon, 29 May 2023 18:09:49 +0200 Subject: [PATCH 1/8] deactivate cache for all vignettes --- vignettes/caching.Rmd | 2 ++ vignettes/customizing_styler.Rmd | 9 +++++++++ vignettes/detect-alignment.Rmd | 7 ++++++- vignettes/distribute_custom_style_guides.Rmd | 2 ++ vignettes/remove_rules.Rmd | 5 ++++- vignettes/strict.Rmd | 2 ++ vignettes/styler.Rmd | 9 +++++++-- 7 files changed, 32 insertions(+), 4 deletions(-) diff --git a/vignettes/caching.Rmd b/vignettes/caching.Rmd index b5f9a7553..b15c7b92a 100644 --- a/vignettes/caching.Rmd +++ b/vignettes/caching.Rmd @@ -12,6 +12,8 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) +options(styler.colored_print.vertical = FALSE) +styler::cache_deactivate() ``` ```{r setup} diff --git a/vignettes/customizing_styler.Rmd b/vignettes/customizing_styler.Rmd index 5a681c435..e566daabd 100644 --- a/vignettes/customizing_styler.Rmd +++ b/vignettes/customizing_styler.Rmd @@ -7,6 +7,15 @@ vignette: > %\VignetteEncoding{UTF-8} --- +```{r} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +options(styler.colored_print.vertical = FALSE) +styler::cache_deactivate() +``` + This vignette provides a high-level overview of how styler works and how you can define your own style guide and format code according to it. If you simply want to customize the tidyverse style guide to your needs, check out `vignette("styler")`, to remove some rules, have a look at `vignette("remove_rules")`. How to distribute a custom style guide is described in `vignette("distribute_custom_style_guides")`. # How styler works diff --git a/vignettes/detect-alignment.Rmd b/vignettes/detect-alignment.Rmd index 937d2921e..b3872d7f5 100644 --- a/vignettes/detect-alignment.Rmd +++ b/vignettes/detect-alignment.Rmd @@ -8,7 +8,12 @@ vignette: > --- ```{r, include=FALSE} -knitr::opts_chunk$set(eval = FALSE) +knitr::opts_chunk$set( + eval = FALSE, + collapse = TRUE, + comment = "#>" +) +styler::cache_deactivate() ``` # Overview diff --git a/vignettes/distribute_custom_style_guides.Rmd b/vignettes/distribute_custom_style_guides.Rmd index 0284facc8..031a13876 100644 --- a/vignettes/distribute_custom_style_guides.Rmd +++ b/vignettes/distribute_custom_style_guides.Rmd @@ -12,6 +12,8 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) +styler::cache_deactivate() +options(styler.colored_print.vertical = FALSE) ``` This vignette describes how you can distribute your own style guide. It builds on `vignette("customizing_styler")` and assumes you understand how to create a style guide with `create_style_guide()`. diff --git a/vignettes/remove_rules.Rmd b/vignettes/remove_rules.Rmd index c0f076239..657538c76 100644 --- a/vignettes/remove_rules.Rmd +++ b/vignettes/remove_rules.Rmd @@ -15,6 +15,7 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) +styler::cache_deactivate() ``` ```{r, echo = FALSE, include = FALSE} @@ -60,7 +61,9 @@ Here are the steps required to deactivate a rule you don't like Lets assume you want to remove the rule that turns `=` into `<-` for assignment. That means you want - string = "hi there" +``` +string = "hi there" +``` to remain unchanged after applying styler. This is not the case if you use the default style guide of styler: diff --git a/vignettes/strict.Rmd b/vignettes/strict.Rmd index f73d98679..880a5db10 100644 --- a/vignettes/strict.Rmd +++ b/vignettes/strict.Rmd @@ -14,6 +14,8 @@ knitr::opts_chunk$set( results = "hide" ) +styler::cache_deactivate() + knitr::knit_engines$set(list( styler = function(options) { options$comment <- "" diff --git a/vignettes/styler.Rmd b/vignettes/styler.Rmd index 2428465fa..dcb451adc 100644 --- a/vignettes/styler.Rmd +++ b/vignettes/styler.Rmd @@ -21,6 +21,7 @@ knitr::knit_engines$set(list( )) options(styler.colored_print.vertical = FALSE) +styler::cache_deactivate() ``` # Entry-points @@ -35,14 +36,18 @@ styler provides the following API to format code: - RStudio Addins for styling the active file, styling the current package and styling the highlighted selection, see `help("styler_addins")`. -Beyond that, styler can be used through other tools documented in the `vignette("third-party-integrations")`. +Beyond that, styler can be used through other tools documented in the `vignette("third-party-integrations")`. Let's get started. +```{r} +library(styler) +``` + + ### Passing arguments to the style guide styler separates the abstract definition of a style guide from the application of it. That's why you must supply a style guide via `transformers` when styling (in case you don't want to rely on the defaults): ```{r} -library(styler) style_text("a + b", transformers = tidyverse_style(scope = "indention")) ``` From a2b9d11100e6fbf6a0c6b3aaf08d6a25887b583c Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Mon, 29 May 2023 18:14:35 +0200 Subject: [PATCH 2/8] move cache clearning into separate test file that is ran at the end. --- tests/testthat/test-cache-clean-up.R | 27 +++++++++++++++++++++++++++ tests/testthat/test-zzz.R | 18 ------------------ 2 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 tests/testthat/test-cache-clean-up.R diff --git a/tests/testthat/test-cache-clean-up.R b/tests/testthat/test-cache-clean-up.R new file mode 100644 index 000000000..ed5dc5b81 --- /dev/null +++ b/tests/testthat/test-cache-clean-up.R @@ -0,0 +1,27 @@ +test_that("styler tests did not use R.cache in user root", { + skip_on_cran() + skip_on_covr() + skip_during_parallel() + expect_true( + length(list.files(R.cache::getCachePath("styler"), recursive = TRUE)) == 0L + ) +}) + +test_that("clear Cache", { + # if R CMD CHECK is running, R.cache root is set to a temp + # directory by default. + # https://github.com/HenrikBengtsson/R.cache/commit/c7ac171f15f035674346d5504049c38cf07c268f + # Hence, this clean up won't clean up the user directory that Ripley is + # concerned about, but only some temp directory. + # On the other hand, it seems completely unclear how the user cache even gets + # populated. + # skip_during_parallel() + cache_path <- R.cache::getCachePath("styler") + R.cache::clearCache(cache_path, recursive = TRUE, prompt = FALSE) + # rlang::abort(paste0('cache path:', cache_path)) + skip_on_cran() + skip_on_covr() + expect_true( + length(list.dirs(R.cache::getCachePath("styler"))) == 1L + ) +}) diff --git a/tests/testthat/test-zzz.R b/tests/testthat/test-zzz.R index f9d01d9f1..dbbee5082 100644 --- a/tests/testthat/test-zzz.R +++ b/tests/testthat/test-zzz.R @@ -1,21 +1,3 @@ -test_that("styler tests did not use R.cache in user root", { - skip_on_cran() - skip_on_covr() - expect_true( - length(list.files(R.cache::getCachePath("styler"), recursive = TRUE)) == 0L - ) -}) - -test_that("clear Cache", { - R.cache::clearCache(R.cache::getCachePath("styler"), recursive = TRUE) - skip_on_cran() - skip_on_covr() - expect_true( - length(list.dirs(R.cache::getCachePath("styler"))) == 1L - ) -}) - - test_that("can delete empty cache directory", { skip_if(getRversion() < package_version("4.0.0")) skip_on_cran() From 611c689075eed1c1d7fcdbe1c285892cb6986ded Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Mon, 29 May 2023 19:40:37 +0200 Subject: [PATCH 3/8] use more concise timeout --- R/zzz.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index bee69d85d..e6e628c66 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -76,7 +76,7 @@ remove_old_cache_files <- function() { path_version_specific, full.names = TRUE, recursive = TRUE ) - date_boundary <- Sys.time() - 60L * 60L * 24L * 6L + date_boundary <- Sys.time() - as.difftime(6, unit = "days") file.remove( all_cached[file.info(all_cached)$mtime < date_boundary] ) From 98127c756030fc01a90023911e6b89586b61dd09 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Mon, 29 May 2023 20:12:23 +0200 Subject: [PATCH 4/8] fix errors --- DESCRIPTION | 2 +- NEWS.md | 10 +++++++++- R/zzz.R | 2 +- tests/testthat/test-cache-clean-up.R | 10 +++------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 94ecae74c..434ff833e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: styler Title: Non-Invasive Pretty Printing of R Code -Version: 1.10.0.9000 +Version: 1.10.1 Authors@R: c(person(given = "Kirill", family = "Müller", diff --git a/NEWS.md b/NEWS.md index 9efbd2658..6dc69a941 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,12 @@ - +# styler 1.10.1 + +This release was requested by CRAN due to accidentally populating a user cache while building vignettes for R >= 4.3.0. + +* Code quality improvements (#1122). +* Bump JamesIves/github-pages-deploy-action from 4.4.1 to 4.4.2 (#1123). + +Thanks to everyone who contributed to this release: [@olivroy](https://github.com/olivroy) and [@krlmlr](https://github.com/krlmlr). + # styler 1.10.0 This release contains speed-ups between 20% and 40% depending on your use case diff --git a/R/zzz.R b/R/zzz.R index e6e628c66..340054b67 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -76,7 +76,7 @@ remove_old_cache_files <- function() { path_version_specific, full.names = TRUE, recursive = TRUE ) - date_boundary <- Sys.time() - as.difftime(6, unit = "days") + date_boundary <- Sys.time() - as.difftime(6L, unit = "days") file.remove( all_cached[file.info(all_cached)$mtime < date_boundary] ) diff --git a/tests/testthat/test-cache-clean-up.R b/tests/testthat/test-cache-clean-up.R index ed5dc5b81..66adce823 100644 --- a/tests/testthat/test-cache-clean-up.R +++ b/tests/testthat/test-cache-clean-up.R @@ -8,17 +8,13 @@ test_that("styler tests did not use R.cache in user root", { }) test_that("clear Cache", { - # if R CMD CHECK is running, R.cache root is set to a temp + # if R CMD CHECK is detected, R.cache root is set to a temp # directory by default. # https://github.com/HenrikBengtsson/R.cache/commit/c7ac171f15f035674346d5504049c38cf07c268f - # Hence, this clean up won't clean up the user directory that Ripley is - # concerned about, but only some temp directory. - # On the other hand, it seems completely unclear how the user cache even gets - # populated. - # skip_during_parallel() + # Hence, this clean up won't clean up the user directory. + skip_during_parallel() cache_path <- R.cache::getCachePath("styler") R.cache::clearCache(cache_path, recursive = TRUE, prompt = FALSE) - # rlang::abort(paste0('cache path:', cache_path)) skip_on_cran() skip_on_covr() expect_true( From c51956ffa600cd6253c67810b5982ba9a94bb978 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Mon, 29 May 2023 20:19:21 +0200 Subject: [PATCH 5/8] update cran comments --- cran-comments.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index 229978c38..ed38adf29 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -4,8 +4,8 @@ editor_options: wrap: 79 --- -This is a release requested by the CRAN team to delete empty directories in the -user's cache. +This is a release requested by the CRAN team to delete the population of the +user's cache while building vignettes. ## Test environments From 82dcfe3cc9343bd72a06c77949a3228788a60485 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 29 May 2023 18:26:39 +0000 Subject: [PATCH 6/8] pre-commit --- inst/WORDLIST | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/WORDLIST b/inst/WORDLIST index b6a53ac74..1e14ad162 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -107,6 +107,7 @@ iNZightTools io ixmypi ized +JamesIves Jupyterlab Kirill kirill From fc5a61d8ed7fba1febda10a70f1cd52936e47e24 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Mon, 29 May 2023 20:40:17 +0200 Subject: [PATCH 7/8] go to bleeding edge --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4bb1af251..a45eaf64f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ default_language_version: repos: - repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9007 + rev: f3498c421d68a1db26de1a1fe3ecc91dd6f03b5e hooks: - id: style-files args: From b1d4793b67416a0ec0427a3b212fc83bea1ebb71 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Tue, 30 May 2023 09:17:31 +0200 Subject: [PATCH 8/8] no partial matching --- R/zzz.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index 340054b67..77b90ee17 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -76,7 +76,7 @@ remove_old_cache_files <- function() { path_version_specific, full.names = TRUE, recursive = TRUE ) - date_boundary <- Sys.time() - as.difftime(6L, unit = "days") + date_boundary <- Sys.time() - as.difftime(6L, units = "days") file.remove( all_cached[file.info(all_cached)$mtime < date_boundary] )