assert: Combine multiple checks into one assertion

View source: R/assert.R

assertR Documentation

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 the packages checkmate, NVIcheckmate or your own functions which return TRUE on success and the error message as character(1) otherwise.

Usage

assert(..., combine = "or", .var.name = NULL, comment = NULL, add = 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.

comment

[character(1)]
Extra information to be appended to the standard error message in assertions.

add

[AssertCollection]
Collection to store assertions. See AssertCollection.

Details

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.

Value

Throws an error (or pushes the error message to an AssertCollection if add is not NULL) if the checks fail and invisibly returns TRUE otherwise.

Examples

x = 1:10
assert(checkmate::checkNull(x), checkmate::checkInteger(x, any.missing = FALSE))
collection <- checkmate::makeAssertCollection()
assert(checkmate::checkChoice(x, c("a", "b")), checkmate::checkDataFrame(x), add = collection)
collection$getMessages()

PetterHopp/NVIcheckmate documentation built on Dec. 15, 2024, 12:49 a.m.