ERRVL {statnet.common} | R Documentation |
Attempt a series of statements and return the first one that is not an error.
Description
ERRVL()
expects the potentially erring statements to be wrapped
in try()
. In addition, all expressions after the first may
contain a .
, which is substituted with the try-error
object
returned by the previous expression.
ERRVL2()
does not require the potentially erring
statements to be wrapped in try()
and will, in fact, treat them
as non-erring; it does not perform dot substitution.
ERRVL3()
behaves as ERRVL2()
, but it does perform
dot-substitution with the condition
object.
Usage
ERRVL(...)
ERRVL2(...)
ERRVL3(...)
Arguments
... |
Expressions to be attempted; for |
Value
The first argument that is not an error. Stops with an error if all are.
Note
This family of functions behave similarly to the NVL()
and the EVL()
families.
These functions use lazy evaluation, so, for example
ERRVL(1, stop("Error!"))
will never evaluate the stop()
call
and will not produce an error, whereas ERRVL2(solve(0), stop("Error!"))
would.
See Also
Examples
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!")))
## End(Not run)
# Capture and print the try-error object:
ERRVL(try(solve(0), silent=TRUE),
print(paste0("Stopped with an error: ", .)))
print(ERRVL2(1,2,3)) # 1
print(ERRVL2(solve(0),2,3)) # 2
print(ERRVL2(1, stop("Error!"))) # No error
## Not run:
# Error:
ERRVL3(solve(0), stop("Error!"))
## End(Not run)
# Capture and print the error object:
ERRVL3(solve(0), print(paste0("Stopped with an error: ", .)))
# Shorthand for tryCatch(expr, error = function(e) e):
ERRVL3(solve(0), .)