Skip to contents

A simpler and more efficient replacement for base::stopifnot(). As opposed to stopifnot(), assert() only works with a single (scalar) assertions.

Usage

assert(cond, ..., call = sys.call(-1))

Arguments

cond

TRUE or FALSE (without any attributes).

  • TRUE will return TRUE

  • FALSE will throw an exception with an automatically constructed error if none was supplied in ....

  • any other value will throw an error indicating that cond was illegal

...

Either character scalars that will be combined with base::paste0() or a single condition object.

Value

TRUE on success

See also

Examples

if (FALSE) {
  assert(1 == 1)
  assert(1 == 2)
  assert(1 == 2, "one is not ", "two")
  assert(1 == 2, errorCondition("one is not two", class = "ObviousError"))
}