% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/predapply.r
\name{predapply}
\alias{predapply}
\title{Apply a predicate function over a list or vector}
\usage{
predapply(X, FUN, ..., reduce = NULL, na.as = NA)
}
\arguments{
\item{X}{a vector (atomic or list) or an expression object.
Other objects (including classed objects) will be coerced by
\code{\link{as.list}}.}

\item{FUN}{a predicate function to be applied to each element of
\code{X} that returns a single logical value.}

\item{...}{optional arguments to \code{FUN}.}

\item{reduce}{\code{NULL} or one of \code{"all"}, \code{"any"}, or \code{"none"}. When
non-\code{NULL}, the output logical vector is reduced to a single boolean
value using \link{all}, \link{any} or \code{"none"} (implemented as \code{all(!logi)}).}

\item{na.as}{logical value to return for \code{NA} values in the output logical
vector (\code{NA}, \code{TRUE} or \code{FALSE}).}
}
\value{
logical vector or boolean if \code{reduce} is non-\code{NULL}.
}
\description{
Returns a logical of the same length as \code{X}, each element of which is
the result of applying predicate \code{FUN} to the corresponding element
of \code{X.}
}
\details{
\code{na.as} is most meaningful when \code{reduce} is non-\code{NULL}, as it allows control
flow calls (e.g., \verb{if (predapply(...))}) to proceed without error.
See examples.
}
\examples{
x <- list(a = 1, b = 2, c = NA)
predapply(x, is.numeric)
predapply(x, is.numeric, reduce = "any")

x <- list(a = 1, b = 2, c = 3)
predapply(x, is.numeric, reduce = "all")

x <- list(a = "1", b = "2", c = "3")
predapply(x, is.numeric, reduce = "none")

x <- c(1, 2, NA)
predapply(x, function(x) x > 0)
predapply(x, function(x) x > 0, reduce = "all")
predapply(x, function(x) x > 0, reduce = "all", na.as = TRUE)
}
\seealso{
\link{apply}, \link{lapply}, \link{mapply}, \link{all}, \link{any}.
}
