powered by
checkWarning checks if a warning is generated by an expression, and optionally follows an expected regular expression pattern.
checkWarning
checkWarning(expr, expected = TRUE, msg = NULL)
checkWarning returns TRUE is the check is successful.
an R expression
expected value as regular expression pattern. If a logical, then it specifies if a warning is expected or not.
For backward compatibility, a NULL value is equivalent to TRUE.
NULL
TRUE
informative message to add to the error in case of failure
# check warnings checkWarning({ warning('ah ah'); 3}) checkWarning({ warning('ah oh ah'); 3}, 'oh') try( checkWarning(3) ) try( checkWarning({ warning('ah ah'); 3}, 'warn you') )
Run the code above in your browser using DataLab