Skip to content

Useful for tests where you want to make sure your function throws an error.

Usage

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

Value

TRUE/FALSE

See also

Author

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

Examples

is.error(  log(3)              )
#> [1] FALSE
is.error(  log("a")            )
#> [1] TRUE
is.error(  log(3),   tell = TRUE )
#> [1] FALSE
is.error(  log("a"), tell = TRUE )
#> Note in is_error: Error in log("a") : non-numeric argument to mathematical function
#> [1] TRUE
stopifnot( is.error( log("a")  )  ) # or shorter:
is.error(  log("a"), force = TRUE)
#> [1] TRUE
# is.error(  log(3),   force = TRUE)
stopifnot(is.error(  is.error(log(3), force = TRUE)  ))