View source: R/misc.utilities.R
ERRVL | R Documentation |
try-error
(result of try
encountering an error.This function is inspired by NVL
, and simply returns the first
argument that is not a try-error
, raising an error if all arguments
are try-error
s.
ERRVL(...)
... |
Expressions to be tested; usually outputs of
|
The first argument that is not a try-error
. Stops
with an error if all are.
This function uses lazy evaluation, so, for example ERRVL(1, stop("Error!"))
will never evaluate the stop
call and will
not produce an error, whereas ERRVL(try(solve(0)), stop("Error!"))
would.
In addition, all expressions after the first may contain a .
,
which is substituted with the try-error
object returned by the
previous expression.
try
, inherits
print(ERRVL(1,2,3)) # 1
print(ERRVL(try(solve(0)),2,3)) # 2
print(ERRVL(1, stop("Error!"))) # No error
## Not run:
# Error:
print(ERRVL(try(solve(0), silent=TRUE),
stop("Error!")))
# Error with an elaborate message:
print(ERRVL(try(solve(0), silent=TRUE),
stop("Stopped with an error: ", .)))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.