assert: Assert

View source: R/assert.R

assertR Documentation

Assert

Description

Raises an assertion error when any(expr) is false.

Usage

assert(
  expr,
  error_message = NULL,
  error_class = NULL,
  call = rlang::caller_call(),
  env = rlang::caller_env(),
  print_expr = NULL,
  ...
)

Arguments

expr

<expression> a logical expression to test.

error_message

<string> a message to be displayed when assertion fails.

error_class

<character> the class name/s for the error.

call

The execution environment of a currently running function, e.g. call = caller_env(). The corresponding function call is retrieved and mentioned in error messages as the source of the error.

You only need to supply call when throwing a condition from a helper function which wouldn't be relevant to mention in the message.

Can also be NULL or a defused function call to respectively not display any call or hard-code a code to display.

env

<environment> the environment for substituted dots and print_expr. Has no effect if dots and print_expr are already quosures.

print_expr

<expression> a diffused expression for altering the error message. Defaults to rlang::as_quosure(substitute(expr), rlang::caller_env())

...

<any> values used in evaluating glue expressions, for the error message.


qfes/tidyassert documentation built on March 19, 2022, 7:18 a.m.