From 37fedfe8d83daa968a416b0e0ec754c359ff24a2 Mon Sep 17 00:00:00 2001
From: Lorenz Walthert <lorenz.walthert@icloud.com>
Date: Mon, 2 Mar 2020 22:07:14 +0100
Subject: [PATCH 1/2] fix examples for cache
---
R/detect-alignment.R | 4 ++++
R/initialize.R | 11 ++++++++---
R/nested-to-tree.R | 14 +++++++++-----
R/utils-navigate-nest.R | 9 +++++++--
man/create_node_from_nested_root.Rd | 14 +++++++++-----
man/default_style_guide_attributes.Rd | 11 ++++++++---
man/next_terminal.Rd | 9 +++++++--
man/token_is_on_aligned_line.Rd | 4 ++++
8 files changed, 56 insertions(+), 20 deletions(-)
diff --git a/R/detect-alignment.R b/R/detect-alignment.R
index 11ef5b9e..72d97f70 100644
--- a/R/detect-alignment.R
+++ b/R/detect-alignment.R
@@ -27,6 +27,9 @@
#' @keywords internal
#' @examples
#' library("magrittr")
+#' withr::with_options(
+#' list(styler.cache_name = NULL), # temporarily deactivate cache
+#' {
#' transformers <- tidyverse_style()
#' pd_nested <- styler:::compute_parse_data_nested(c(
#' "call(",
@@ -37,6 +40,7 @@
#' styler:::post_visit(transformers$initialize)
#' nest <- pd_nested$child[[1]]
#' styler:::token_is_on_aligned_line(nest)
+#' })
token_is_on_aligned_line <- function(pd_flat) {
line_idx <- 1 + cumsum(pd_flat$lag_newlines)
pd_flat$.lag_spaces <- lag(pd_flat$spaces)
diff --git a/R/initialize.R b/R/initialize.R
index a7618411..fce38b34 100644
--- a/R/initialize.R
+++ b/R/initialize.R
@@ -5,9 +5,14 @@
#' @param pd_flat A parse table.
#' @importFrom utils tail
#' @examples
-#' string_to_format <- "call( 3)"
-#' pd <- styler:::compute_parse_data_nested(string_to_format)
-#' styler:::pre_visit(pd, c(default_style_guide_attributes))
+#' withr::with_options(
+#' list(styler.cache_name = NULL), # temporarily deactivate cache
+#' {
+#' string_to_format <- "call( 3)"
+#' pd <- styler:::compute_parse_data_nested(string_to_format)
+#' styler:::pre_visit(pd, c(default_style_guide_attributes))
+#' }
+#' )
#' @export
#' @keywords internal
default_style_guide_attributes <- function(pd_flat) {
diff --git a/R/nested-to-tree.R b/R/nested-to-tree.R
index dc5af094..eaf1c6e7 100644
--- a/R/nested-to-tree.R
+++ b/R/nested-to-tree.R
@@ -30,11 +30,15 @@ create_tree_from_pd_with_default_style_attributes <- function(pd, structure_only
#' @return An object of class "Node" and "R6".
#' @examples
#' if (rlang::is_installed("data.tree")) {
-#' cache_deactivate() # keep things simple
-#' code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
-#' nested_pd <- styler:::compute_parse_data_nested(code)
-#' initialized <- styler:::pre_visit(nested_pd, c(default_style_guide_attributes))
-#' styler:::create_node_from_nested_root(initialized, structure_only = FALSE)
+#' withr::with_options(
+#' list(styler.cache_name = NULL), # temporarily deactivate cache
+#' {
+#' code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
+#' nested_pd <- styler:::compute_parse_data_nested(code)
+#' initialized <- styler:::pre_visit(nested_pd, c(default_style_guide_attributes))
+#' styler:::create_node_from_nested_root(initialized, structure_only = FALSE)
+#' }
+#' )
#' }
#' @keywords internal
create_node_from_nested_root <- function(pd_nested, structure_only) {
diff --git a/R/utils-navigate-nest.R b/R/utils-navigate-nest.R
index 029e3a9a..00ab0b18 100644
--- a/R/utils-navigate-nest.R
+++ b/R/utils-navigate-nest.R
@@ -48,8 +48,13 @@ previous_non_comment <- function(pd, pos) {
#' nested structure.
#' @keywords internal
#' @examples
-#' pd <- styler:::compute_parse_data_nested("if (TRUE) f()")
-#' styler:::next_terminal(pd)
+#' withr::with_options(
+#' list(styler.cache_name = NULL), # temporarily deactivate cache
+#' {
+#' pd <- styler:::compute_parse_data_nested("if (TRUE) f()")
+#' styler:::next_terminal(pd)
+#' }
+#' )
next_terminal <- function(pd,
stack = FALSE,
vars = c("pos_id", "token", "text"),
diff --git a/man/create_node_from_nested_root.Rd b/man/create_node_from_nested_root.Rd
index 4177ac4a..fc4c8628 100644
--- a/man/create_node_from_nested_root.Rd
+++ b/man/create_node_from_nested_root.Rd
@@ -22,11 +22,15 @@ at once.
}
\examples{
if (rlang::is_installed("data.tree")) {
- cache_deactivate() # keep things simple
- code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
- nested_pd <- styler:::compute_parse_data_nested(code)
- initialized <- styler:::pre_visit(nested_pd, c(default_style_guide_attributes))
- styler:::create_node_from_nested_root(initialized, structure_only = FALSE)
+ withr::with_options(
+ list(styler.cache_name = NULL), # temporarily deactivate cache
+ {
+ code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
+ nested_pd <- styler:::compute_parse_data_nested(code)
+ initialized <- styler:::pre_visit(nested_pd, c(default_style_guide_attributes))
+ styler:::create_node_from_nested_root(initialized, structure_only = FALSE)
+ }
+ )
}
}
\keyword{internal}
diff --git a/man/default_style_guide_attributes.Rd b/man/default_style_guide_attributes.Rd
index 83461bbe..3f26b285 100644
--- a/man/default_style_guide_attributes.Rd
+++ b/man/default_style_guide_attributes.Rd
@@ -14,8 +14,13 @@ This function initializes and removes various variables from the parse
table.
}
\examples{
-string_to_format <- "call( 3)"
-pd <- styler:::compute_parse_data_nested(string_to_format)
-styler:::pre_visit(pd, c(default_style_guide_attributes))
+withr::with_options(
+ list(styler.cache_name = NULL), # temporarily deactivate cache
+ {
+ string_to_format <- "call( 3)"
+ pd <- styler:::compute_parse_data_nested(string_to_format)
+ styler:::pre_visit(pd, c(default_style_guide_attributes))
+ }
+)
}
\keyword{internal}
diff --git a/man/next_terminal.Rd b/man/next_terminal.Rd
index 7e898d18..d9548249 100644
--- a/man/next_terminal.Rd
+++ b/man/next_terminal.Rd
@@ -37,7 +37,12 @@ If the first is a terminal, return it. If not, go inside it and search the
next terminal
}
\examples{
-pd <- styler:::compute_parse_data_nested("if (TRUE) f()")
-styler:::next_terminal(pd)
+withr::with_options(
+ list(styler.cache_name = NULL), # temporarily deactivate cache
+ {
+ pd <- styler:::compute_parse_data_nested("if (TRUE) f()")
+ styler:::next_terminal(pd)
+ }
+)
}
\keyword{internal}
diff --git a/man/token_is_on_aligned_line.Rd b/man/token_is_on_aligned_line.Rd
index 0f68c69c..b9ca9b60 100644
--- a/man/token_is_on_aligned_line.Rd
+++ b/man/token_is_on_aligned_line.Rd
@@ -36,6 +36,9 @@ sure we can stop as soon as we found that columns are not aligned.
}
\examples{
library("magrittr")
+withr::with_options(
+ list(styler.cache_name = NULL), # temporarily deactivate cache
+ {
transformers <- tidyverse_style()
pd_nested <- styler:::compute_parse_data_nested(c(
"call(",
@@ -46,5 +49,6 @@ pd_nested <- styler:::compute_parse_data_nested(c(
styler:::post_visit(transformers$initialize)
nest <- pd_nested$child[[1]]
styler:::token_is_on_aligned_line(nest)
+})
}
\keyword{internal}
From ce6817f063d3580cd0934fadccd7e4f657060b7e Mon Sep 17 00:00:00 2001
From: Lorenz Walthert <lorenz.walthert@icloud.com>
Date: Mon, 2 Mar 2020 23:07:54 +0100
Subject: [PATCH 2/2] fix failing macOS test with microbenhmark dependency by a
rewrite
---
vignettes/performance_improvements.Rmd | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/vignettes/performance_improvements.Rmd b/vignettes/performance_improvements.Rmd
index 1f87e144..b57bf88a 100644
--- a/vignettes/performance_improvements.Rmd
+++ b/vignettes/performance_improvements.Rmd
@@ -11,12 +11,9 @@ vignette: >
---
We want to make styler faster.
-```{r, echo = FALSE}
-knitr::opts_chunk$set(eval = FALSE)
-```
-```{r}
+```
library(styler)
microbenchmark::microbenchmark(
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
@@ -28,7 +25,9 @@ microbenchmark::microbenchmark(
```
Replacing mutate statements.
-```{r}
+
+```
+
microbenchmark::microbenchmark(
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
times = 2
@@ -39,7 +38,8 @@ microbenchmark::microbenchmark(
```
Move `opening` argument out of needs indention.
-```{r}
+
+```
microbenchmark::microbenchmark(
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
times = 5
@@ -51,7 +51,8 @@ microbenchmark::microbenchmark(
```
Dropping unnecessary select statements and arrange stuff.
-```{r}
+
+```
microbenchmark::microbenchmark(
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
times = 5
@@ -63,7 +64,8 @@ microbenchmark::microbenchmark(
Some more stuff (early return, purr)
-```{r}
+
+```
microbenchmark::microbenchmark(
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
times = 5
@@ -74,7 +76,8 @@ microbenchmark::microbenchmark(
```
Various changes (positive and negative in terms of speed)
-```{r}
+
+```
microbenchmark::microbenchmark(
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
times = 10
@@ -87,7 +90,8 @@ microbenchmark::microbenchmark(
Removed tibble bottlenecks (tibble 1.4.2, https://github.com/tidyverse/tibble/pull/348)
-```{r}
+
+```
microbenchmark::microbenchmark(
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
times = 10