Skip to contents

assert() is a drop-in replacement for stopifnot() that supports more informative error messages.

Usage

assert(..., msg = NULL)

Arguments

...

Any number of R expressions that return logical(1), each of which should evaluate to TRUE. Rather than combining expressions with &&, separate them by commas so that better error messages can be generated.

msg

NULL or character(1). Custom message to return.

Value

TRUE on success, error on failure.

Details

If any of the expressions defined in ... are TRUE, stop() is called, producing an error message indicating the first expression which was not TRUE.

Note

Updated 2021-10-08.

See also

  • stopifnot().

  • assertthat::assert_that().

  • assertive.base::assert_engine().

  • checkmate::assert().

Examples

assert(
    is.atomic("example"),
    is.character("example")
)