assert: Assert a condition

View source: R/utils-sfmisc.R

assertR Documentation

Assert a condition

Description

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

assert_all()

Examples

## Not run: 
  assert(1 == 1)
  assert(1 == 2)
  assert(1 == 2, "one is not ", "two")
  assert(1 == 2, errorCondition("one is not two", class = "ObviousError"))

## End(Not run)

s-fleck/sfmisc documentation built on Nov. 21, 2023, 12:29 a.m.