Skip to content

Instantly share code, notes, and snippets.

@yihui yihui/warnings.R
Created Sep 22, 2013

Embed
What would you like to do?
this shows the correct way to suppress warnings is suppressWarnings() instead of options(warn = -1) alone; similarly, you should use suppressMessages() to suppress messages
options(warn = -1)
# cannot really suppress warnings from the root level
withCallingHandlers(warning("hi"), warning = function(w) {
print(w)
})
# the warning can still be captured:
## <simpleWarning in withCallingHandlers(warning("hi"), warning = function(w) { print(w)}): hi>
# however, this always works
withCallingHandlers(suppressWarnings(warning("hi")), warning = function(w) {
print(w)
})
# even if when warn=0
options(warn = 0)
withCallingHandlers(suppressWarnings(warning("hi")), warning = function(w) {
print(w)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.