Skip to content

Commit 270ea25

Browse files
Merge branch 'master' into vs-code
2 parents daece85 + f7cea77 commit 270ea25

21 files changed

+320
-119
lines changed

NEWS.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11

22
# styler 1.5.1.9000 (Development version)
33

4-
* Files with `.Rmarkdown` extension are now recognized as an R markdown files in `style_file()` and friends (#824).
4+
* Files with `.Rmarkdown` extension are now recognized as an R markdown files in
5+
`style_file()` and friends (#824).
56

67
* Don't break line before comments in pipes (#822).
78

8-
* Ordinary comments (starting with `#`) within a roxygen code example block
9+
* Ordinary comments (starting with `#`) that break a roxygen code example block
910
(starting with `#'`) are now recognized and preserved (#830).
1011

12+
* `@examplesIf` conditions longer than one line after styling throw an error for
13+
compatibility with {roxygen2} (#833).
14+
15+
* R Markdown chunk headers are no longer required to be parsable R code (#832).
16+
1117
* Break the line between `%>%` and `{` inside and outside function calls (#825).
1218

13-
* Add language server to the integrations (#835).
19+
* Add language server to third-party integrations vignette (#835).
20+
21+
* improved test setup with fixtures and similar (#798).
22+
1423

1524
# styler 1.5.1
1625

R/roxygen-examples.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@ style_roxygen_code_example <- function(example, transformers, base_indention) {
2525
style_roxygen_code_example_one <- function(example_one, transformers, base_indention) {
2626
bare <- parse_roxygen(example_one)
2727
one_dont <- split(bare$text, factor(cumsum(bare$text %in% dont_keywords())))
28-
map(one_dont, style_roxygen_code_example_segment,
28+
unmasked <- map(one_dont, style_roxygen_code_example_segment,
2929
transformers = transformers,
3030
base_indention = base_indention
3131
) %>%
32-
flatten_chr() %>%
32+
flatten_chr()
33+
if (bare$example_type == "examplesIf") {
34+
with_handlers(
35+
parse_text(unmasked[1]),
36+
error = function(e) {
37+
abort(paste0(
38+
"Could not style condition in `@examplesIf` because it would result ",
39+
"in multi-line condition, which is currently not supported in ",
40+
"{roxygen2} (see https://github.com/r-lib/roxygen2/issues/1242)."
41+
))
42+
}
43+
)
44+
}
45+
unmasked %>%
3346
add_roxygen_mask(example_one, bare$example_type)
3447
}
3548

R/testing.R

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,24 +257,19 @@ n_times_faster_with_cache <- function(x1, x2 = x1, ...,
257257
out <- purrr::map(1:n, n_times_faster_bench,
258258
x1 = x1, x2 = x2, fun = fun,
259259
..., n = n, clear = clear
260-
) %>%
260+
)
261+
out <- out %>%
261262
purrr::map_dbl(
262263
~ unname(.x$first["elapsed"] / .x$second["elapsed"])
263264
) %>%
264265
mean()
265266

266-
if (clear %in% c("always", "final")) {
267-
clear_testthat_cache()
268-
}
269267
out
270268
}
271269

272270

273271
n_times_faster_bench <- function(i, x1, x2, fun, ..., n, clear) {
274-
fresh_testthat_cache()
275-
if ((clear == "always") || (clear == "all but last" & n != i)) {
276-
on.exit(clear_testthat_cache())
277-
}
272+
local_test_setup(cache = TRUE)
278273
first <- system.time(fun(x1, ...))
279274

280275
if (is.null(x2)) {
@@ -284,7 +279,8 @@ n_times_faster_bench <- function(i, x1, x2, fun, ..., n, clear) {
284279
}
285280
list(
286281
first = first,
287-
second = second
282+
second = second,
283+
cache = cache_info(format = "tabular")
288284
)
289285
}
290286

@@ -333,9 +329,34 @@ generate_test_samples <- function() {
333329
#' @include ui-caching.R
334330
clear_testthat_cache <- purrr::partial(cache_clear, "testthat", ask = FALSE)
335331
activate_testthat_cache <- purrr::partial(cache_activate, "testthat")
336-
fresh_testthat_cache <- function() {
337-
clear_testthat_cache()
338-
activate_testthat_cache()
332+
333+
#' Establish testing setup for current environment
334+
#'
335+
#' @param cache Whether or not to create and activate a cache in a temporary
336+
#' directory.
337+
#' @param .local_envir The environment to use for scoping.
338+
#' @details
339+
#' * make styler quiet.
340+
local_test_setup <- function(cache = FALSE,
341+
.local_envir = parent.frame()) {
342+
current_cache <- cache_info(format = "tabular")
343+
withr::local_options(
344+
list("styler.quiet" = TRUE, "R.cache.rootPath" = tempfile()),
345+
.local_envir = .local_envir
346+
)
347+
if (cache) {
348+
withr::defer(
349+
{
350+
clear_testthat_cache()
351+
cache_activate(basename(current_cache$location))
352+
if (!current_cache$activated) {
353+
cache_deactivate()
354+
}
355+
},
356+
envir = .local_envir
357+
)
358+
activate_testthat_cache()
359+
}
339360
}
340361

341362
cache_more_specs_default <- function() {

R/transform-code.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ identify_raw_chunks <- function(lines, filetype, engine_pattern = get_engine_pat
117117
#' @keywords internal
118118
finalize_raw_chunks <- function(start, end, filetype, lines) {
119119
header <- gsub(get_knitr_pattern(filetype)$chunk.begin, "\\2", lines[start])
120-
parsed <- get_parse_data(paste0("c(", header, ")"))$text
121-
do_not_tidy <- any(parsed == "tidy") &&
122-
parsed[which(parsed == "tidy") + 1] == "=" &&
123-
parsed[which(parsed == "tidy") + 2] == "FALSE"
124-
if (do_not_tidy) {
125-
return(NULL)
120+
# matches last , tidy = TRUE, ignoring quotes!
121+
extracted_false <- gsub(
122+
".*,\\s*\\t*tidy\\s*\\t*=\\s*\\t*(F|FALSE)(\\s+.*|\\t+.*|,+.*|)$",
123+
"\\1",
124+
header
125+
)
126+
if (extracted_false %in% c("F", "FALSE")) {
127+
NULL
126128
} else {
127129
list(starts = start, ends = end)
128130
}

R/ui-caching.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ cache_info <- function(cache_name = NULL, format = "both") {
112112
#' function is doing.
113113
#' @family cache managers
114114
#' @export
115-
cache_activate <- function(cache_name = NULL, verbose = !getOption("styler.quiet", FALSE)) {
115+
cache_activate <- function(cache_name = NULL,
116+
verbose = !getOption("styler.quiet", FALSE)) {
116117
if (!is.null(cache_name)) {
117118
options("styler.cache_name" = cache_name)
118119
} else {

man/local_test_setup.Rd

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

tests/testthat/rmd/no-tidy-in.Rmd

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,49 @@ test + f(1)
1616
```{r}
1717
test + f(1)
1818
```
19+
20+
```{r, A = ', tidy = FALSE,'}
21+
knitr::opts_chunk$set(echo = TRUE )
22+
```
23+
24+
```{r, A = ', tidy = FALSE}'}
25+
knitr::opts_chunk$set(echo = TRUE )
26+
```
27+
28+
```{r, A = ', tidy = FALSE'}
29+
knitr::opts_chunk$set(echo = TRUE )
30+
```
31+
32+
```{r, A = 'tidy = FALSE, and more'}
33+
knitr::opts_chunk$set(echo = TRUE )
34+
```
35+
36+
37+
```{r, tidy = TRUE}
38+
knitr::opts_chunk$set(echo = TRUE )
39+
```
40+
41+
```{r, a = ',tidy = FALSE'}
42+
knitr::opts_chunk$set(echo = TRUE )
43+
```
44+
45+
```{r, a = ',tidy = TRUE'}
46+
knitr::opts_chunk$set(echo = TRUE )
47+
```
48+
49+
50+
```{r, tidy = FALSE, aniopts= 3}
51+
knitr::opts_chunk$set(echo = TRUE )
52+
```
53+
54+
```{r, tidy= FALSE, aniopts= 3}
55+
knitr::opts_chunk$set(echo = TRUE )
56+
```
57+
58+
```{r, tidy =FALSE, aniopts= 3}
59+
knitr::opts_chunk$set(echo = TRUE )
60+
```
61+
62+
```{r, aniopts= 3, tidy = FALSE}
63+
knitr::opts_chunk$set(echo = TRUE )
64+
```

tests/testthat/rmd/no-tidy-out.Rmd

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,49 @@ test + f(1)
1616
```{r}
1717
test + f(1)
1818
```
19+
20+
```{r, A = ', tidy = FALSE,'}
21+
knitr::opts_chunk$set(echo = TRUE )
22+
```
23+
24+
```{r, A = ', tidy = FALSE}'}
25+
knitr::opts_chunk$set(echo = TRUE)
26+
```
27+
28+
```{r, A = ', tidy = FALSE'}
29+
knitr::opts_chunk$set(echo = TRUE)
30+
```
31+
32+
```{r, A = 'tidy = FALSE, and more'}
33+
knitr::opts_chunk$set(echo = TRUE)
34+
```
35+
36+
37+
```{r, tidy = TRUE}
38+
knitr::opts_chunk$set(echo = TRUE)
39+
```
40+
41+
```{r, a = ',tidy = FALSE'}
42+
knitr::opts_chunk$set(echo = TRUE)
43+
```
44+
45+
```{r, a = ',tidy = TRUE'}
46+
knitr::opts_chunk$set(echo = TRUE)
47+
```
48+
49+
50+
```{r, tidy = FALSE, aniopts= 3}
51+
knitr::opts_chunk$set(echo = TRUE )
52+
```
53+
54+
```{r, tidy= FALSE, aniopts= 3}
55+
knitr::opts_chunk$set(echo = TRUE )
56+
```
57+
58+
```{r, tidy =FALSE, aniopts= 3}
59+
knitr::opts_chunk$set(echo = TRUE )
60+
```
61+
62+
```{r, aniopts= 3, tidy = FALSE}
63+
knitr::opts_chunk$set(echo = TRUE )
64+
```

0 commit comments

Comments
 (0)