knitr 1.35
NEW FEATURES
-
Chunk options can also be written inside a code chunk now after the special comment
#|
, e.g.,```{r} #| echo = FALSE, fig.width = 10, #| fig.cap = "This is a long caption." plot(cars) ```
The main differences between this new syntax and traditional syntax (i.e., chunk options in the chunk header) are: 1) the chunk options can be freely wrapped, i.e., you can write them on as many lines as you prefer; 2) you can also use the YAML syntax instead of the comma-separated syntax if you like, e.g.,
```{r} #| echo: false #| fig.width: 10 ```
Chunk options provided inside a code chunk will override options with the same names in the chunk header if chunk options are provided in both places, e.g.,
```{r, echo = TRUE} #| echo = FALSE, fig.width = 10 ```
The effective chunk options for the above chunk are
echo = FALSE
andfig.width = 10
.
MAJOR CHANGES
-
For R Markdown documents, if the chunk header is indented, the closing backticks (usually
```
) of the chunk must be indented with the same amount of spaces (thanks, @atusy, #2047). For example, the following is no longer a valid code chunk because the chunk header is indented but the closing backticks are not:```{r} 1 + 1 ```
If you see an error "attempt to use zero-length variable name" when knitting an Rmd document, it may be because of this change, and you may have indented the chunk header by accident. If that is the case, you need to remove the extra white spaces before the chunk header.
The same problem applies to blockquotes, i.e.,
>
before```
. If you quote the chunk header, you have to quote the footer as well, e.g.,> ```{r} 1 + 1 ```
The above unbalanced code chunk needs to be corrected to:
> ```{r} > 1 + 1 > ```
Quoting the chunk body is optional but recommended.
BUG FIXES
-
Fixed a regression in v1.34: now blank lines in code chunks are stripped only when
collapse = FALSE
but no longer stripped by default whencollapse = TRUE
. If you prefer blank lines to be always stripped, setstrip.white = TRUE
globally or on the per chunk basis (thanks, @IndrajeetPatil, rstudio/rmarkdown#2220, #2046). -
In
knitr::combine_words()
, whenwords
is length 2 andand = ""
,sep
will now be used (thanks, @eitsupi, #2044). -
For R Markdown documents, if the chunk output contains N backticks, the
output
hook will use N + 1 backticks to wrap the output, so that the N verbatim backticks can be correctly preserved (thanks, @atusy, #2047).