except {infix} | R Documentation |
Simple Error Handling
Description
Use this method to handle errors. The function evaluates an expression, and if it raises an error then evaluates a second expression.
Usage
tryExcept(expr, except = { }, error = function(e) { })
expr %except% except
Arguments
expr |
Expression to be evaluated. |
except |
Expression to be evaluated if |
error |
Handler function for an |
Details
tryExcept
is a wrapper around tryCatch
,
but it allows you to evaluate an expression except
when an error occurs to
the first expression argument expr
. Note that, if expr
raises
an error, the code evaluated before the error will be in use.
Examples
# No errors are raised
tryExcept(stop())
# If 'expr' has no errors
tryExcept({
foo <- "foo"
}, except = {
foo <- "foo bar"
})
print(foo) # "foo"
# If 'expr' has an error
tryExcept({
foo <- "foo"
stop()
}, except = {
foo <- "foo bar"
})
print(foo) # "foo bar"
# Running it with the infix operator
{foo <- "foo"} %except% {foo <- "foo bar"}
print(foo) # "foo"
{ foo <- "foo"
stop()
} %except% {
foo <- "foo bar"
}
print(foo) # "foo bar"
[Package infix version 0.1.0 Index]