stopifnot
Stop if Not All True
Description
Evaluates one or more logical expressions and, if any of the
expressions in the argument list is not TRUE, stop
is called. An error message is printed indicating the first
FALSE expression encountered, and then the calling
function exits.
Usage
stopifnot(..., exprs, exprObject, local = TRUE)
Arguments
... |
One or more logical expressions that should evaluate to TRUE.
Logical vectors must contain only TRUE values.
|
exprs |
Instead of using ..., one can use a braced list of logical-valued expressions
with the logical-valued expressions in it.
|
exprObject |
Instead of using ... or exprs, one can use an expression object
containing the logical-valued expressions.
|
local |
If you use the exprs or exprObject arguments, then the local argument specifies in
which environment to evaluate the logical-valued expressions (otherwise local is ignored). If local
is not an environment, then it should be either TRUE (evaluate in the caller's
frame) or FALSE (evaluate in the global environment).
|
Side Effects
stopifnot evaluates each expression and calls stop if the result is not TRUE
or a vector of TRUEs, which terminates execution of the current expression.
The error message includes the offending logical-valued expression unless the expression
is given in name=expr form, in which case name will be used.
See Also
Examples
z <- function(x)
{
stopifnot(length(x) > 0, LOG_TOO_BIG=log(x) > 1)
stopifnot(exprs = {
x < 50
x > 7
})
exp(sum(log(x)))
}
z(10:12)
## Not run:
z(numeric(0))
z(1:4)
z(4:9)
stopifnot(all.equal(pi, 3.14), all(1:10 < 12), "d" < "b")
stopifnot(all.equal(pi, 3.1415927), all(1:10 < 12), "d" < "b")
## End(Not run)