stopifnot {base} | R Documentation

## Ensure the 'Truth' of R Expressions

### Description

If any of the expressions in `...` are not `all` `TRUE`, `stop` is called, producing an error message indicating the first element of `...` which was not true.

### Usage

    stopifnot(...)

### Arguments

`...` | any number of (`logical`) R expressions which should evaluate to `TRUE`.

### Details

`stopifnot(A, B)` is conceptually equivalent to `{ if(!all(A)) stop(...) ; if(!all(B)) stop(...) }`.

### Value

(`NULL` if all statements in `...` are `TRUE`.)

### See Also

`stop`, `warning`.

### Examples

    stopifnot(1 == 1, all.equal(pi, 3.14159265), 1 < 2) # all TRUE

    m <- matrix(c(1,3,3,1), 2,2)
    stopifnot(m == t(m), diag(m) == rep(1,2)) # all(.) |=>  TRUE

    options(error = expression(NULL))# "disable stop(.)"  << Use with CARE! >>

    stopifnot(all.equal(pi, 3.141593),  2 < 2, all(1:10 < 12), "a" < "b")
    stopifnot(all.equal(pi, 3.1415927), 2 < 2, all(1:10 < 12), "a" < "b")

    options(error = NULL)# revert to default error handler

[Package Contents]