View source: R/suppress_warnings.R
suppress_warnings | R Documentation |
Sometimes R throws warning messages that we don't want to see. The base
suppressWarnings()
function permits one to suppress warnings, but
it is tricky to selectively suppress only certain warnings on the basis
of a regular expression or another condition. This function allows one
to do that.
suppress_warnings(.expr, .f, ...)
.expr |
Expression to be evaluated. |
.f |
String or function. If a string (possibly representing a
regular expression), any warning message generated when |
... |
Additional arguments to be passed to |
Most functions in the Bullock package have camelCase names. This one does
not: it would ordinarily have been called suppressWarnings
, but
that name is taken by a function in base\NBR.
The function was created by Antoine Fabri ("Moody_Mudskipper"): see https://stackoverflow.com/a/55182432/697473.
suppress_warnings( {sqrt(-1); warning("oops", call. = FALSE)}, startsWith, "o" ) # Warning message: # In sqrt(-1) : NaNs produced suppress_warnings( {sqrt(-1); warning("oops", call. = FALSE)}, ~nchar(.)>10 ) # Warning message: # oops suppress_warnings( {sqrt(-1); warning("ooops", call. = FALSE)}, "NaN" ) # Warning message: # oops suppress_warnings( {sqrt(-1); invisible()}, "NaN" ) # Nothing is printed.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.