I have a .Rmd file containing nothing but the following code chunks A, B, and C.
```{r A}
options("width") # => 96 on my system
```
```{r B}
options(width = 60)
options("width") # => 60
```
```{r C}
options("width") # => 96 but I expected 60
```
When I open a fresh instance of RStudio, open the .Rmd file, clear the knitr cache using RStudio's "Clear Knitr Cache..." Knit-menu item, and run the chunks, one by one, in the listed order using RStudio's chunk-specific "Run Current Chunk" buttons, I get 96, the default width on my system, for chunk A, 60 for chunk B, and 96 for chunk C.
Why does the new global width set in chunk B not persist into chunk C?
I am using RStudio version 1.4.1717 with rmarkdown version 2.10 and knitr version 1.34 on macOS Catalina.
A similar question about options(digits = N)
was asked here and the single answer was accepted by the asker. However, the example given in the answer fails to demonstrate persistence of R's global options across chunks as the relevant code chunks include their own options(digits = ...)
calls. When I tested the example from that answer on my system using an additional code chunk without options(digits = ...)
call, the "digits" value set in the previous chunk did not persist.