Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ERRVL

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

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

Common R Scripts and Utilities Used by the Statnet Project Software

v4.4.1
GPL-3 + file LICENSE
Authors
Pavel N. Krivitsky [aut, cre] (<https://orcid.org/0000-0002-9101-3362>), Skye Bender-deMoll [ctb]
Initial release
2020-10-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.