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

AssertCollection

Collect multiple assertions


Description

The function makeAssertCollection() returns a simple stack-like closure you can pass to all functions of the assert*-family. All messages get collected and can be reported with reportAssertions(). Alternatively, you can easily write your own report function or customize the the output of the report function to a certain degree. See the example on how to push custom messages or retrieve all stored messages.

Usage

makeAssertCollection()

reportAssertions(collection)

Arguments

collection

[AssertCollection]
Object of type “AssertCollection” (constructed via makeAssertCollection).

Value

makeAssertCollection() returns an object of class “AssertCollection” and reportCollection returns invisibly TRUE if no error is thrown (i.e., no message was collected).

Examples

x = "a"
coll = makeAssertCollection()

print(coll$isEmpty())
assertNumeric(x, add = coll)
coll$isEmpty()
coll$push("Custom error message")
coll$getMessages()
## Not run: 
  reportAssertions(coll)

## 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.