is_error: Check if an expression returns an error

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/helper_functions.R

Description

Does a given expression return an error?

Usage

1
is_error(expr, tell = FALSE, force = FALSE)

Arguments

expr

Expression to be tested for returning an error

tell

Logical: Should the error message be printed via message? DEFAULT: FALSE

force

Logical: Should an error be returned if the expression is not an error? DEFAULT: FALSE

Details

Useful for tests where you want to make sure your function throws an error. This function was imported from the berryFunctions package.

Value

TRUE/FALSE

Author(s)

Berry Boessenkool, berry-b@gmx.de, May 2016

See Also

stop, try, inherits

Other helper functions: key_valid()

Examples

1
2
3
4
5
6
7
8
is_error(  log(3)              )
is_error(  log("a")            )
is_error(  log(3),   tell=TRUE )
is_error(  log("a"), tell=TRUE )
stopifnot( is_error( log("a")  )  ) # or shorter:
is_error(  log("a"), force=TRUE)
# is_error(  log(3),   force=TRUE)
stopifnot(is_error(  is_error(log(3), force=TRUE)  ))

jknappe/ubzutils documentation built on Sept. 1, 2020, 6:44 p.m.