InterceptExceptions | R Documentation |
This function intercepts warning and error messages produced
from running expr
and passes them to warning.handler
and
error.handler
. Note that execution of expr is stopped after the
first error.
InterceptExceptions(expr, warning.handler = NULL, error.handler = NULL)
expr |
The expression whose warnings are to be intercepted. |
warning.handler |
The function that handles intercepted warnings. |
error.handler |
The function that handles intercepted errors. |
The value from evaluating expr
.
addExclamationMark <- function(warn)
{
warning(warn$message, "!")
}
## Intercepts a warning and rethrows it with an
## exclamation mark.
InterceptExceptions(warning("This is a warning"),
warning.handler = addExclamationMark)
addQuestionMark <- function(error)
{
warning(error$message, "?")
}
## Intercepts the error from throwsAWarning and rethrows it with an
## exclamation mark.
InterceptExceptions(stop("Stop"), error.handler = addQuestionMark)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.