Description Usage Arguments Details Examples
Use this method to handle errors. The function evaluates an expression, and if it raises an error then evaluates a second expression.
1 2 3 |
expr |
Expression to be evaluated. |
except |
Expression to be evaluated if |
error |
Handler function for an |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # 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"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.