\HeaderA{stopifnot}{Ensure the `Truth' of R Expressions}{stopifnot}
\keyword{environment}{stopifnot}
\keyword{programming}{stopifnot}
\keyword{error}{stopifnot}
\begin{Description}\relax
If any of the expressions in \code{...} are not \code{\LinkA{all}{all}}
\code{TRUE}, \code{\LinkA{stop}{stop}} is called, producing an error message
indicating the \emph{first} of the elements of \code{...} which were
not true.
\end{Description}
\begin{Usage}
\begin{verbatim}
stopifnot(...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{...}] any number of (\code{\LinkA{logical}{logical}}) \R{} expressions,
which should evaluate to \code{\LinkA{TRUE}{TRUE}}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This function is intended for use in regression tests or also argument
checking of functions, in particular to make them easier to read.

\code{stopifnot(A, B)} is conceptually equivalent to
\code{\{ if(any(is.na(A)) || !all(A)) stop(...) ;
           if(any(is.na(B)) || !all(B)) stop(...) \}}.
\end{Details}
\begin{Value}
(\code{\LinkA{NULL}{NULL}} if all statements in \code{...} are \code{TRUE}.)
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{stop}{stop}}, \code{\LinkA{warning}{warning}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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

op <- 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(op)# revert to previous error handler
\end{ExampleCode}
\end{Examples}

