Skip to contents

All functions take logical or logical-like (i.e., 1, 0, or NA as integer or doubles) and return logical values.

Extensions to the base logical operations to account for NA values.

base::isTRUE() and base::isFALSE() will only return single length TRUE or FALSE as it checks for valid lengths in the evaluation. When needing to check over a vector for the presence of TRUE or FALSE and not being held back by NA values, is_true and is_false will always provide a TRUE FALSE when the vector is logical or return NA is the vector x is not logical.

%or% is just a wrapper for base::xor()

Usage

is_true(x)

# S3 method for default
is_true(x)

# S3 method for logical
is_true(x)

is_false(x)

# S3 method for default
is_false(x)

# S3 method for logical
is_false(x)

x %xor% y

OR(..., na.rm = FALSE)

AND(..., na.rm = FALSE)

either(x, y)

is_boolean(x)

none(..., na.rm = FALSE)

Arguments

x, y

A vector of logical values. If NULL will generate a warning. If not a logical value, will return NA equal to the vector length

...

Vectors or a list of logical values

na.rm

Logical, if TRUE will ignore NA

Value

  • is_true(), is_false(), either(), %or%, AND(), OR(): A logical vector, equal length of x (or y or of all ... lengths)

  • is_boolean(): TRUE or FALSE

  • none(): TRUE, FALSE, or NA

Details

Logical operations, extended

Examples

x <- c(TRUE, FALSE, NA)
y <- c(FALSE, FALSE, TRUE)
z <- c(TRUE, NA, TRUE)
isTRUE(x)
#> [1] FALSE
is_true(x)
#> [1]  TRUE FALSE FALSE
isFALSE(x)
#> [1] FALSE
is_false(x)
#> [1] FALSE  TRUE FALSE
x %xor% TRUE
#> [1] FALSE  TRUE    NA
TRUE %xor% TRUE
#> [1] FALSE
TRUE %xor% FALSE
#> [1] TRUE
NA %xor% FALSE
#> [1] NA
OR(x, y, z)
#> [1] TRUE   NA TRUE
OR(x, y, z, na.rm = TRUE)
#> [1]  TRUE FALSE  TRUE
AND(x, y, z)
#> [1] FALSE FALSE    NA
AND(x, y, z, na.rm = TRUE)
#> [1] FALSE FALSE  TRUE
either(x, FALSE)
#> [1]  TRUE FALSE FALSE
either(TRUE, FALSE)
#> [1] TRUE
either(FALSE, NA)
#> [1] FALSE
either(TRUE, NA)
#> [1] TRUE
none(x)
#> [1] FALSE
none(x & y, na.rm = TRUE)
#> [1] TRUE
is_boolean(x)
#> [1] TRUE
is_boolean(c(1L, NA_integer_, 0L))
#> [1] TRUE
is_boolean(c(1.01, 0, -1))
#> [1] FALSE