logic_ext {mark} | R Documentation |
Logic - Extension'
Description
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)
## Default S3 method:
is_true(x)
## S3 method for class 'logical'
is_true(x)
is_false(x)
## Default S3 method:
is_false(x)
## S3 method for class '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 |
... |
Vectors or a list of logical values |
na.rm |
Logical, if |
Details
Logical operations, extended
Value
-
is_true()
,is_false()
,either()
,%or%
,AND()
,OR()
: Alogical
vector, equal length ofx
(ory
or of all...
lengths) -
is_boolean()
:TRUE
orFALSE
-
none()
:TRUE
,FALSE
, orNA
Examples
x <- c(TRUE, FALSE, NA)
y <- c(FALSE, FALSE, TRUE)
z <- c(TRUE, NA, TRUE)
isTRUE(x)
is_true(x)
isFALSE(x)
is_false(x)
x %xor% TRUE
TRUE %xor% TRUE
TRUE %xor% FALSE
NA %xor% FALSE
OR(x, y, z)
OR(x, y, z, na.rm = TRUE)
AND(x, y, z)
AND(x, y, z, na.rm = TRUE)
either(x, FALSE)
either(TRUE, FALSE)
either(FALSE, NA)
either(TRUE, NA)
none(x)
none(x & y, na.rm = TRUE)
is_boolean(x)
is_boolean(c(1L, NA_integer_, 0L))
is_boolean(c(1.01, 0, -1))