assertionError: Condition classes

Description Usage Arguments Value Note Examples

View source: R/conditions.R

Description

Error, warning, and message classes derived from their simple equivalents.

Usage

1
2
3
4
5
assertionError(message, call = NULL, predicate_name = NULL)

assertionWarning(message, call = NULL, predicate_name = NULL)

assertionMessage(message, call = NULL, predicate_name = NULL)

Arguments

message

A string describing the problem.

call

A call describing the source of the condition.

predicate_name

A string naming the predicate that was called when the condition occured.

Value

An object of class assertionError, assertionWarning, or assertionMessage.

Note

These objects behave the same as the standard-issue simpleError, simpleWarning, and simpleMessage objects from base-R. The extra class allows you to provide custom handling for assertions inside tryCatch.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
tryCatch(
  assert_all_are_true(FALSE), 
  error = function(e) 
  {
    if(inherits(e, "assertionCondition"))
    {
      # Handle assertions
      message("This is an assertion condition.")
      
      # Handle assertions cause by a specific predicate
      if(e$predicate_name == "is_true")
      {
      }
    } else
    {
      # Handle other error types
    }
  }
)

Example output

This is an assertion condition.
NULL

assertive.base documentation built on Feb. 8, 2021, 9:06 a.m.