% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stopifnot.r
\name{stopifnot.with}
\alias{stopifnot.with}
\title{Ensure the Truth of R Expressions in a Data Environment}
\usage{
stopifnot.with(data, ..., call. = TRUE)
}
\arguments{
\item{data}{data to use for constructing an environment. This may be an
\code{environment}, a \code{list}, a \code{data.frame}, or an \code{integer} as in
\code{sys.call}.}

\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 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.}
}
\value{
If no errors are thrown, the function returns \code{data} invisibly.
}
\description{
Wrapper around \link{stopifnot2} that evaluates \strong{R} expressions
in an environment constructed from \code{data}.
}
\details{
If any of the expressions are not \link{all} \code{TRUE}, \link{stop} is called,
producing an error message indicating the first expression which
was not (\link{all}) true. See \link{stopifnot} and \link{stopifnot2} for full details.

Special care must be taken for handlers on the call stack, as they
may affect the call displayed in the error message. In
such instances, passing an environment to \code{call.} may be helpful.
}
\examples{
try(stopifnot.with(data.frame(x = 1, y = 2), x == y))
try(stopifnot.with(list(x = 1, y = 2), all.equal(x, y)))

f1 <- function(x, ..., call.) stopifnot.with(x, ..., call. = call.)
f2 <- function(x, ..., call.) f1(x, ..., call. = call.)
f <- function(x, ..., call.) f2(x, ..., call. = call.)

x <- list(a = 1, b = 2)
try(f(x, a == b, call. = FALSE))
try(f(x, a == b, call. = TRUE))

try(f(x, a == 1, b < 1, call. = 0))
try(f(x, b > 3, call. = 1))
try(f(x, a != 1, call. = 2))

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

try(f(x, a == 1, b < 1))
}
\seealso{
\link{stop2} and \link{warning2} for errors and warnings
with call information.
}
