[bug] Rmd file does not respect options(warn = ) across chunks #2357
Closed
Description
Hello,
There seems to be an issue in how the R warning option (options()$warn
) is handled inside an Rmd file.
This might be related to an older issue #1425 (comment)
The warn option does not correctly persist across the Rmd file chunks.
Here is an example code to test the behaviour:
```{r part1}
f <- function(x) {warning("Warning raised!"); x}
options(warn = 0)
options()$warn
f(TRUE)
```
#>[1] 0
#>[1] TRUE
#>Warning message:
#>In f(TRUE) : Warning raised!
```{r part2}
options(warn = 1)
options()$warn
f(TRUE)
options(warn = 2)
```
#>[1] 1
#>Warning in f(TRUE) : Warning raised!
#>[1] TRUE
```{r ops-fail}
options()$warn
f(TRUE)
```
#>[1] 1
#>Warning in f(TRUE) : Warning raised!
#>[1] TRUE
Last options()$warn reports value of 1, and thus the last call to f() does not raise an error, even though the option was explicitly set in the previous code chunk.
This should not be related to the evaluate
package, as it only handles evaluation of a single chunk
I hope this is helpful.
Session info:
xfun::session_info("rmarkdown")
R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22621), RStudio c(2024, 4, 2, 764)
Locale:
LC_COLLATE=Finnish_Finland.utf8 LC_CTYPE=Finnish_Finland.utf8
LC_MONETARY=Finnish_Finland.utf8 LC_NUMERIC=C
LC_TIME=Finnish_Finland.utf8
Package version:
base64enc_0.1.3 bslib_0.7.0 cachem_1.1.0 cli_3.6.3
digest_0.6.36 evaluate_0.24.0 fastmap_1.2.0 fontawesome_0.5.2
fs_1.6.4 glue_1.7.0 graphics_4.4.1 grDevices_4.4.1
highr_0.11 htmltools_0.5.8.1 jquerylib_0.1.4 jsonlite_1.8.8
knitr_1.48.1 lifecycle_1.0.4 memoise_2.0.1 methods_4.4.1
mime_0.12 R6_2.5.1 rappdirs_0.3.3 rlang_1.1.4
rmarkdown_2.27 sass_0.4.9 stats_4.4.1 tinytex_0.52
tools_4.4.1 utils_4.4.1 xfun_0.46 yaml_2.3.9
Pandoc version: 3.1.11
By filing an issue to this repo, I promise that
- I have fully read the issue guide at https://yihui.org/issue/.
- I have provided the necessary information about my issue.
- If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
- If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
. - If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- I have learned the Github Markdown syntax, and formatted my issue correctly.
I understand that my issue may be closed if I don't fulfill my promises.