Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

assert

Combine multiple checks into one assertion


Description

You can call this function with an arbitrary number of of check* functions, i.e. functions provided by this package or your own functions which return TRUE on success and the error message as character(1) otherwise. The resulting assertion is successful, if combine is “or” (default) and at least one check evaluates to TRUE or combine is “and” and all checks evaluate to TRUE. Otherwise, assert throws an informative error message.

Usage

assert(..., combine = "or", .var.name = NULL)

Arguments

...

[any]
List of calls to check functions.

combine

[character(1)]
“or” or “and” to combine the check functions with an OR or AND, respectively.

.var.name

[character(1)]
Name of the checked object to print in error messages. Defaults to the heuristic implemented in vname.

Value

Throws an error if all checks fail and invisibly returns TRUE otherwise.

Examples

x = 1:10
assert(checkNull(x), checkInteger(x, any.missing = FALSE))
## Not run: 
x = 1
assert(checkChoice(x, c("a", "b")), checkDataFrame(x))

## End(Not run)

checkmate

Fast and Versatile Argument Checks

v2.0.0
BSD_3_clause + file LICENSE
Authors
Michel Lang [cre, aut] (<https://orcid.org/0000-0001-9754-0393>), Bernd Bischl [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.