Assert a condition
assert.Rd
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
orFALSE
(without any attributes).TRUE
will returnTRUE
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 withbase::paste0()
or a singlecondition
object.
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"))
}