Skip to content
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

options(warn = ) doesn't work #1425

Closed
yutannihilation opened this issue Aug 19, 2017 · 5 comments · Fixed by r-lib/evaluate#81
Closed

options(warn = ) doesn't work #1425

yutannihilation opened this issue Aug 19, 2017 · 5 comments · Fixed by r-lib/evaluate#81
Milestone

Comments

@yutannihilation
Copy link
Collaborator

yutannihilation commented Aug 19, 2017

?options says:

If warn is zero (the default) warnings are stored until the top–level function returns. (snip) If warn is one, warnings are printed as they occur. If warn is two or larger all warnings are turned into errors.

But, it seems this option doesn't work during knitting. The bellow is an example result by reprex::reprex(). Is this a known issue?

f <- function(x) {
  warning("You've been warned!")
  x
}

options(warn = 0)
options()$warn
#> [1] 0
f(TRUE)
#> Warning in f(TRUE): You've been warned!
#> [1] TRUE

options(warn = 1)
options()$warn
#> [1] 1
f(TRUE)
#> Warning in f(TRUE): You've been warned!
#> [1] TRUE

options(warn = 2)
options()$warn
#> [1] 2
f(TRUE)
#> Warning in f(TRUE): You've been warned!
#> [1] TRUE
@yihui
Copy link
Owner

yihui commented Aug 19, 2017

I think this issue belongs to the evaluate package. I'm not sure about the reason, but to my knowledge, only options(warn = -1) will work. Please feel free to study the source code of evaluate, and submit a pull request if you can figure out a fix. Thanks!

https://github.com/hadley/evaluate/blob/5caf63450e479cff1fdce617923e097c0f072809/R/eval.r#L186-L188

https://github.com/hadley/evaluate/blob/5caf63450e479cff1fdce617923e097c0f072809/R/eval.r#L142-L149

@yutannihilation
Copy link
Collaborator Author

Thanks for the infomation! I will study and file a issue or send PR to evaluate :)

@yihui yihui added this to the v0.18 milestone Aug 20, 2017
@yihui
Copy link
Owner

yihui commented Aug 20, 2017

Thanks!

@yutannihilation
Copy link
Collaborator Author

I found you've explained this in detail, which is really helpful. Thanks!

#610 (comment)

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants