tryNULL: Try Catch Returns NULL

tryNULLR Documentation

Try Catch Returns NULL

Description

A convenient wrapper to capture errors in an expression returning NULL rather than error out. This simplifies error catching for downstream functionality via is.null(). See try() and tryCatch().

Usage

tryNULL(expr, default = NULL, quiet = TRUE)

Arguments

expr

An R expression to try.

default

The value to return if an error is encountered. By default, and according to the function name, NULL. This option is included for the rare case when something other than NULL is desired.

quiet

Logical. Should the error message (if encountered) be printed?

Value

Either the value of the expression in expr or, if an error is encountered, the value in default.

Author(s)

Stu Field

References

More or less "borrowed" from the plyr package.

See Also

try(), tryCatch()

Examples

tryNULL(log("a"))
tryNULL(log("a"), quiet = FALSE)
tryNULL(log("a"), default = 0)

stufield/stuRpkg documentation built on April 2, 2022, 2:05 p.m.