ERRVL: Return the first argument passed (out of any number) that is...

View source: R/misc.utilities.R

ERRVLR Documentation

Return the first argument passed (out of any number) that is not a try-error (result of try encountering an error.

Description

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-errors.

Usage

ERRVL(...)

Arguments

...

Expressions to be tested; usually outputs of try.

Value

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

Note

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.

See Also

try, inherits

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!")))

# Error with an elaborate message:
print(ERRVL(try(solve(0), silent=TRUE),
            stop("Stopped with an error: ", .)))

## End(Not run)

statnet.common documentation built on Oct. 6, 2024, 5:06 p.m.