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.

ERRVL(...)

ERRVL2(...)

ERRVL3(...)

Arguments

...

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

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.

Examples


print(ERRVL(1,2,3)) # 1
#> [1] 1
print(ERRVL(try(solve(0)),2,3)) # 2
#> Error in solve.default(0) : 
#>   Lapack routine dgesv: system is exactly singular: U[1,1] = 0
#> [1] 2
print(ERRVL(1, stop("Error!"))) # No error
#> [1] 1

if (FALSE) { # \dontrun{
# 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: ", .)))
#> [1] "Stopped with an error: Error in solve.default(0) : \n  Lapack routine dgesv: system is exactly singular: U[1,1] = 0\n"
#> [1] "Stopped with an error: Error in solve.default(0) : \n  Lapack routine dgesv: system is exactly singular: U[1,1] = 0\n"

print(ERRVL2(1,2,3)) # 1
#> [1] 1
print(ERRVL2(solve(0),2,3)) # 2
#> [1] 2
print(ERRVL2(1, stop("Error!"))) # No error
#> [1] 1


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

# Capture and print the error object:
ERRVL3(solve(0), print(paste0("Stopped with an error: ", .)))
#> [1] "Stopped with an error: Error in solve.default(0): Lapack routine dgesv: system is exactly singular: U[1,1] = 0\n"

# Shorthand for tryCatch(expr, error = function(e) e):
ERRVL3(solve(0), .)
#> <simpleError in solve.default(0): Lapack routine dgesv: system is exactly singular: U[1,1] = 0>