-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathevery.Rd
More file actions
52 lines (46 loc) · 1.51 KB
/
every.Rd
File metadata and controls
52 lines (46 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/every-some-none.R
\name{every}
\alias{every}
\alias{some}
\alias{none}
\title{Do every, some, or none of the elements of a list satisfy a predicate?}
\usage{
every(.x, .p, ...)
some(.x, .p, ...)
none(.x, .p, ...)
}
\arguments{
\item{.x}{A list or vector.}
\item{.p}{A predicate function (i.e. a function that returns either \code{TRUE}
or \code{FALSE}) specified in one of the following ways:
\itemize{
\item A named function, e.g. \code{is.character}.
\item An anonymous function, e.g. \verb{\\(x) all(x < 0)} or \code{function(x) all(x < 0)}.
\item A formula, e.g. \code{~ all(.x < 0)}. Use \code{.x} to refer to the first argument.
No longer recommended.
}}
\item{...}{Additional arguments passed on to \code{.p}.}
}
\value{
A logical vector of length 1.
}
\description{
\itemize{
\item \code{some()} returns \code{TRUE} when \code{.p} is \code{TRUE} for at least one element.
\item \code{every()} returns \code{TRUE} when \code{.p} is \code{TRUE} for all elements.
\item \code{none()} returns \code{TRUE} when \code{.p} is \code{FALSE} for all elements.
}
}
\examples{
x <- list(0:10, 5.5)
x |> every(is.numeric)
x |> every(is.integer)
x |> some(is.integer)
x |> none(is.character)
# Missing values are propagated:
some(list(NA, FALSE), identity)
# If you need to use these functions in a context where missing values are
# unsafe (e.g. in `if ()` conditions), make sure to use safe predicates:
if (some(list(NA, FALSE), rlang::is_true)) "foo" else "bar"
}