Skip to contents

Returns TRUE if any nonmissing values in a logical vector are TRUE.

Usage

any2(x)

Arguments

x

(logical)
The logical vector to be checked if any element is TRUE.

Value

Scalar logical

Details

Missing values are excluded before evaluation. Compared with base::any(), any2() has stricter behavior:

  • any2() never returns NA.

  • any2() returns FALSE for non-logical input.

  • any2() returns FALSE for logical(0) and NULL.

See also

Examples

#----------------------------------------------------------------------------
# any2() examples
#----------------------------------------------------------------------------
library(bkbase)

x <- c(1, 2, 3, NA)
any2(x < 0)
#> [1] FALSE
any(x < 0, na.rm = TRUE)
#> [1] FALSE
any(x < 0, na.rm = FALSE)
#> [1] NA

any2(NA)
#> [1] FALSE
any(NA)
#> [1] NA

any2(1L)
#> [1] FALSE
any(1L)
#> [1] TRUE

any2(c(TRUE, NA))
#> [1] TRUE
any2(c(FALSE, NA))
#> [1] FALSE
any2(c(NA, NA))
#> [1] FALSE

any2(logical(0))
#> [1] FALSE
any(logical(0))
#> [1] FALSE

any2(NULL)
#> [1] FALSE
any(NULL)
#> [1] FALSE