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

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 not all TRUE, stop is called, producing an error message indicating the first expression which was not TRUE.

Note

Updated 2021-08-19.

See also

Examples

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