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(...)

Arguments

... One or more logical expressions that should evaluate to TRUE. Logical vectors must contain only TRUE values.
Side Effects
stopifnot calls stop, which terminates execution of the current expression. The error message includes the first expression in ... that is not all TRUE.
See Also
stop,
Examples
z <- function(x)
{
    stopifnot(length(x) > 0, log(x) > 1)
    exp(sum(log(x)))
}
z(10:12)
#  [1] 1320
## Not run: 
z(numeric(0))     
#  Error in z(numeric(0)) : length(x) > 0 is not TRUE
z(1:4)     
#  Error in z(1:4) : log(x) > 1 is not all TRUE

stopifnot(all.equal(pi, 3.14), all(1:10 < 12), "d" < "b") # Error: all.equal(pi, 3.14) is not TRUE stopifnot(all.equal(pi, 3.1415927), all(1:10 < 12), "d" < "b") # Error: "d" < "b" is not TRUE ## End(Not run)

Package base version 4.0.0-28
Package Index