Skip to content

Commit 9407503

Browse files
Merge pull request #614 from lorenzwalthert/issue-613
- Fix examples for cache (#614).
2 parents f1b3f81 + ce6817f commit 9407503

9 files changed

+70
-30
lines changed

R/detect-alignment.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#' @keywords internal
2828
#' @examples
2929
#' library("magrittr")
30+
#' withr::with_options(
31+
#' list(styler.cache_name = NULL), # temporarily deactivate cache
32+
#' {
3033
#' transformers <- tidyverse_style()
3134
#' pd_nested <- styler:::compute_parse_data_nested(c(
3235
#' "call(",
@@ -37,6 +40,7 @@
3740
#' styler:::post_visit(transformers$initialize)
3841
#' nest <- pd_nested$child[[1]]
3942
#' styler:::token_is_on_aligned_line(nest)
43+
#' })
4044
token_is_on_aligned_line <- function(pd_flat) {
4145
line_idx <- 1 + cumsum(pd_flat$lag_newlines)
4246
pd_flat$.lag_spaces <- lag(pd_flat$spaces)

R/initialize.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
#' @param pd_flat A parse table.
66
#' @importFrom utils tail
77
#' @examples
8-
#' string_to_format <- "call( 3)"
9-
#' pd <- styler:::compute_parse_data_nested(string_to_format)
10-
#' styler:::pre_visit(pd, c(default_style_guide_attributes))
8+
#' withr::with_options(
9+
#' list(styler.cache_name = NULL), # temporarily deactivate cache
10+
#' {
11+
#' string_to_format <- "call( 3)"
12+
#' pd <- styler:::compute_parse_data_nested(string_to_format)
13+
#' styler:::pre_visit(pd, c(default_style_guide_attributes))
14+
#' }
15+
#' )
1116
#' @export
1217
#' @keywords internal
1318
default_style_guide_attributes <- function(pd_flat) {

R/nested-to-tree.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ create_tree_from_pd_with_default_style_attributes <- function(pd, structure_only
3030
#' @return An object of class "Node" and "R6".
3131
#' @examples
3232
#' if (rlang::is_installed("data.tree")) {
33-
#' cache_deactivate() # keep things simple
34-
#' code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
35-
#' nested_pd <- styler:::compute_parse_data_nested(code)
36-
#' initialized <- styler:::pre_visit(nested_pd, c(default_style_guide_attributes))
37-
#' styler:::create_node_from_nested_root(initialized, structure_only = FALSE)
33+
#' withr::with_options(
34+
#' list(styler.cache_name = NULL), # temporarily deactivate cache
35+
#' {
36+
#' code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
37+
#' nested_pd <- styler:::compute_parse_data_nested(code)
38+
#' initialized <- styler:::pre_visit(nested_pd, c(default_style_guide_attributes))
39+
#' styler:::create_node_from_nested_root(initialized, structure_only = FALSE)
40+
#' }
41+
#' )
3842
#' }
3943
#' @keywords internal
4044
create_node_from_nested_root <- function(pd_nested, structure_only) {

R/utils-navigate-nest.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ previous_non_comment <- function(pd, pos) {
4848
#' nested structure.
4949
#' @keywords internal
5050
#' @examples
51-
#' pd <- styler:::compute_parse_data_nested("if (TRUE) f()")
52-
#' styler:::next_terminal(pd)
51+
#' withr::with_options(
52+
#' list(styler.cache_name = NULL), # temporarily deactivate cache
53+
#' {
54+
#' pd <- styler:::compute_parse_data_nested("if (TRUE) f()")
55+
#' styler:::next_terminal(pd)
56+
#' }
57+
#' )
5358
next_terminal <- function(pd,
5459
stack = FALSE,
5560
vars = c("pos_id", "token", "text"),

man/create_node_from_nested_root.Rd

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

man/default_style_guide_attributes.Rd

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

man/next_terminal.Rd

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

man/token_is_on_aligned_line.Rd

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

vignettes/performance_improvements.Rmd

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ vignette: >
1111
---
1212

1313
We want to make styler faster.
14-
```{r, echo = FALSE}
15-
knitr::opts_chunk$set(eval = FALSE)
16-
```
1714

1815

19-
```{r}
16+
```
2017
library(styler)
2118
microbenchmark::microbenchmark(
2219
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
@@ -28,7 +25,9 @@ microbenchmark::microbenchmark(
2825
```
2926

3027
Replacing mutate statements.
31-
```{r}
28+
29+
```
30+
3231
microbenchmark::microbenchmark(
3332
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
3433
times = 2
@@ -39,7 +38,8 @@ microbenchmark::microbenchmark(
3938
```
4039

4140
Move `opening` argument out of needs indention.
42-
```{r}
41+
42+
```
4343
microbenchmark::microbenchmark(
4444
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
4545
times = 5
@@ -51,7 +51,8 @@ microbenchmark::microbenchmark(
5151
```
5252

5353
Dropping unnecessary select statements and arrange stuff.
54-
```{r}
54+
55+
```
5556
microbenchmark::microbenchmark(
5657
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
5758
times = 5
@@ -63,7 +64,8 @@ microbenchmark::microbenchmark(
6364

6465

6566
Some more stuff (early return, purr)
66-
```{r}
67+
68+
```
6769
microbenchmark::microbenchmark(
6870
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
6971
times = 5
@@ -74,7 +76,8 @@ microbenchmark::microbenchmark(
7476
```
7577

7678
Various changes (positive and negative in terms of speed)
77-
```{r}
79+
80+
```
7881
microbenchmark::microbenchmark(
7982
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
8083
times = 10
@@ -87,7 +90,8 @@ microbenchmark::microbenchmark(
8790

8891

8992
Removed tibble bottlenecks (tibble 1.4.2, https://github.com/tidyverse/tibble/pull/348)
90-
```{r}
93+
94+
```
9195
microbenchmark::microbenchmark(
9296
base = style_file("tests/testthat/indention_multiple/overall-in.R"),
9397
times = 10

0 commit comments

Comments
 (0)