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

assertionError

Condition classes


Description

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

Usage

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

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
    }
  }
)

assertive.base

A Lightweight Core of the 'assertive' Package

v0.0-9
GPL (>= 3)
Authors
Richard Cotton [aut, cre], Sunkyu Choi [trl], Ivanka Skakun [trl], Gergely Dar<c3><b3>czi [trl], Anton Antonov [trl], Hisham Ben Hamidane [trl], Anja Billing [trl], Aditya Bhagwat [trl], Rasmus B<c3><a5><c3><a5>th [trl], Mine Cetinkaya-Rundel [trl], Aspasia Chatziefthymiou [trl]
Initial release
2021-02-07

We don't support your browser anymore

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