Learn R Programming

statnet.common (version 4.13.0)

ERRVL: 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(...)

Value

The first argument that is not an error. Stops with an error if all are.

Arguments

...

Expressions to be attempted; for ERRVL(), should be wrapped in try().

See Also

Examples

Run this code

print(ERRVL(1,2,3)) # 1
print(ERRVL(try(solve(0)),2,3)) # 2
print(ERRVL(1, stop("Error!"))) # No error

if (FALSE) {
# Error:
print(ERRVL(try(solve(0), silent=TRUE),
            stop("Error!")))
}

# 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


if (FALSE) {
# Error:
ERRVL3(solve(0), stop("Error!"))
}

# 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), .)

Run the code above in your browser using DataLab