Skip to content

Commit 85f41ef

Browse files
Merge pull request #832 from lorenzwalthert/issue-831
- Allow non-parsable code in headers (#831).
2 parents 027d5b1 + 74b1f1f commit 85f41ef

File tree

4 files changed

+104
-7
lines changed

4 files changed

+104
-7
lines changed

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
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

89
* Ordinary comments (starting with `#`) within a roxygen code example block
910
(starting with `#'`) are now recognized and preserved (#830).
1011

12+
* R Markdown chunk headers are no longer required to be parsable R code (#832).
13+
1114
* Break the line between `%>%` and `{` inside and outside function calls (#825).
1215

1316
# styler 1.5.1

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
}

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)