All: Test if all items in an object evaluate to TRUE.

Description Usage Arguments Value See Also Examples

View source: R/All.R

Description

All() is a predicate functional that takes a predicate function .f and an iterable object .x and:

  1. iterates over each item i in object .x,

  2. evaluates .f(i),

  3. and ultimately returns TRUE if all items i in object .x evaluate as TRUE.

Usage

1
All(.x, .f, ..., na.rm = FALSE)

Arguments

.x

An iterable object.

.f

A predicate function.

...

Further arguments passed to the predicate function.

na.rm

A logical value indicating whether NA values should be stripped before the computation proceeds.

Value

A logical value indicating if all items evaluated as TRUE.

See Also

Any to test if all items in an object evaluate to TRUE.

Other predicate functionals: Any; Reject

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Examples
data(mtcars)
All(mtcars, is.numeric) # TRUE
All(mtcars, is.character) # FALSE
mtcars$am <- factor(mtcars$am)
All(mtcars, is.numeric) # FALSE
All(mtcars, is.factor) # FALSE

# Handles NAs and NULLs
All(list(NA, "3", NULL), is.numeric) # FALSE
All(list(NA, 3, NULL), is.numeric) # FALSE
All(list(NA, "3", NULL, 5), is.numeric) # FALSE

# Use na.rm = TRUE to remove NAs and NULLS
All(list(NA, TRUE), Identity) # NA
All(list(NA, TRUE), Identity, na.rm = TRUE) # TRUE

paulhendricks/functools documentation built on May 24, 2019, 8:41 p.m.