try_catch {msgr} | R Documentation |
Try to evaluate an expressions and capture any messages, warnings or errors
Description
This function is similar to tryCatch()
, except that, by default, errors are captured
and presented using error()
. Messages and warnings are not captured by this function.
In addition, a "finally" expression can be specified which is evaluated at the end of
the call no matter the result.
Usage
try_catch(expr, on_error, finally)
Arguments
expr |
(expression) The expression to evaluate |
on_error |
(function, optional) A function describing what to do in the event of a
error in the above expression. The function must take a single argument, which is the
|
finally |
(expression, optional) An expression to evaluate at the end of the call.
If missing or |
Value
The result of the evaluated expression
Examples
## Not run:
try_catch(x <- "foo")
try_catch(stop("This is an error"))
## End(Not run)