% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stopifnot.r
\name{stopifnot2}
\alias{stopifnot2}
\alias{warningifnot}
\title{Ensure the Truth of R Expressions with Call Information}
\usage{
stopifnot2(..., call. = TRUE)

warningifnot(..., warn.all = FALSE, call. = TRUE)
}
\arguments{
\item{...}{any number of \strong{R} expressions, which should each evaluate
to (a logical vector of \link{all}) \code{\link{TRUE}}. If named, the names will be used
in lieu of the default error/warning message.}

\item{call.}{call, logical, integer, or environment. logical, indicating
if the calling call should become part of the error message with same
semantics as \link{stop}. integer, specifying how many calls to go 'up'
the call stack to extract a call for the message. A value of
\code{0} will give the call to \code{stop2()} itself, \code{1} will give the
call of the caller, and so on. Numeric values are coerced to integer
and absolute values are taken. Values outside either boundary of the
call stack will be clamped to the nearest boundary. environment,
which will be matched against the calling stack and the corresponding
call will be shown.}

\item{warn.all}{logical, indicating if all failed expressions should produce
warnings, or only the first failed expression. Default is \code{FALSE},
which means only the first failed expression will produce a warning.}
}
\value{
Called for side effects only.
}
\description{
Wrapper around \link{stopifnot} that leaves only the \code{...} argument and
adds a \code{call.} argument that shows a call in the message that
is derived from the call stack. \code{warningifnot()} implements the same
functionality but produces a warning instead of an error.
}
\details{
If any of the expressions are not \link{all} \code{TRUE}, \link{stop} or \link{warning}
is called, producing an error/warning message indicating the first
(or all, if \code{warn.all = TRUE} for \code{warningifnot()}) expression
which was not (\link{all}) true. See \link{stopifnot} for full details.

Special care must be taken for handlers on the call stack, as they
may affect the call displayed in the error or warning message. In
such instances, passing an environment to \code{call.} may be helpful.
}
\examples{
f1 <- function(call.) stopifnot2(1 == 2, call. = call.)
f2 <- function(call.) f1(call. = call.)
f <- function(call.) f2(call. = call.)

try(f(call. = FALSE))
try(f(call. = TRUE))

try(f(call. = 0))
try(f(call. = 1))
try(f(call. = 2))

f <- function() {
  e <- environment()
  f1(call. = e)
}

try(f())

try(stopifnot2(all.equal(1, 2)))

warningifnot(1 == 2, 2 == 3)
warningifnot(1 == 2, 2 == 3, warn.all = TRUE)
}
\seealso{
\link{stopifnot.with} for a data-masked version of this function.
}
