-
-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Rmd file does not respect options(warn = ) across chunks #2357
Comments
Could there be a solution similar to the According to this other SO post, also setting other The behaviour should be consistent whether knitting or running as chunks (i.e. setting |
I tried this document ---
output: html_document
---
```{r part1}
f <- function(x) {warning("Warning raised!"); x}
options(warn = 0)
options()$warn
f(TRUE)
```
```{r part2}
options(warn = 1)
options()$warn
f(TRUE)
options(warn = 2)
```
```{r ops-fail}
options()$warn
f(TRUE)
``` Then ---
output: html_document
---
``` r
f <- function(x) {warning("Warning raised!"); x}
options(warn = 0)
options()$warn
```
```
## [1] 0
```
``` r
f(TRUE)
```
```
## Warning in f(TRUE): Warning raised!
```
```
## [1] TRUE
```
``` r
options(warn = 1)
options()$warn
```
```
## [1] 1
```
``` r
f(TRUE)
```
```
## Warning in f(TRUE): Warning raised!
```
```
## [1] TRUE
```
``` r
options(warn = 2)
```
``` r
options()$warn
```
```
## [1] 2
```
``` r
f(TRUE)
```
```
## Error in f(TRUE): (converti depuis l'avis) Warning raised!
``` Doing
So it seems to be working to me ... I am not sure what are the differences, I tried to use the same knitr and evaluate version as you shared.
Note that you can use ---
output: html_document
---
```{r}
options(dummy="I am global")
```
```{r}
getOption("dummy")
```
```{r ops-fail}
getOption("dummy")
```
What would you expect differently ?
You refered to a 2 years old SO post with an answered (https://stackoverflow.com/a/69151906/3436535) explaining this only happens in Notebook mode. Meaning when cells are ran interactively, which is a feature of RStudio IDE or VSCODE extension, depending on what you are using. Are you report about using Hope this helps |
Sorry that I was unclear in my original post. As a copy of your example, when running interactively: ```{r}
options(dummy="I am global")
options(warn=2)
```
```{r ops-fail}
getOption("dummy")
getOption("warn")
```
#>[1] "I am global"
#>[1] 1
```{r ops-fail2}
getOption("dummy")
getOption("warn")
```
#>[1] "I am global"
#>[1] 1 (When knitting, the output is as expected.) Custom options behave correctly even in interactive mode, but something is tampering with the Would you recommend moving this issue to RStudio? |
This is definitely a RStudio IDE discussion then. rmarkdown or knitr are not controlling how chunk are ran inside RStudio IDE.
Yes - this is on there end, and possibly So opening an issue there is the right move for this - we can't do anything on our end here. |
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:
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 chunkI hope this is helpful.
Session info:
By filing an issue to this repo, I promise that
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')
.I understand that my issue may be closed if I don't fulfill my promises.
The text was updated successfully, but these errors were encountered: