Stop if not All True

DESCRIPTION:

stop is called if any of the expressions in the argument list are not TRUE. An error message is printed indicating the first FALSE expression encountered and the calling function is exited.

USAGE:

stopifnot(...)

OPTIONAL ARGUMENTS:

...
one or more logical expressions that should evaluate to TRUE.

SIDE EFFECTS:

stopifnot prints the function call containing the call to stopifnot, followed by the error message, then terminates execution of the current expression and creates a dump. The error message will show the first expression in ... that was not TRUE.

DETAILS:

The function all is applied to each logical expression in the argument list. For example, stopifnot(X,Y) calls stop if either all(X) or all(Y) is FALSE.

This function emulates R's stopifnot function, but produces an error message that includes the name of the function calling stopifnot .

SEE ALSO:

, .

EXAMPLES:

z <- function(x)
{
        stopifnot(length(x) > 0, log(x) > 1)
        exp(sum(log(x)))
}
z(1:4)     
#  Problem in z(1:4): log(x) > 1 is not TRUE
z(10:12)
#  [1] 1320

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