Created
September 22, 2013 04:05
-
-
Save yihui/6656584 to your computer and use it in GitHub Desktop.
this shows the correct way to suppress warnings is suppressWarnings() instead of options(warn = -1) alone; similarly, you should use suppressMessages() to suppress messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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