Learn R Programming

assertive.base (version 0.0-1)

Truth: Is the input TRUE/FALSE/NA?

Description

Checks to see if the input is TRUE, FALSE or NA.

Usage

assert_is_identical_to_false(x, allow_attributes = FALSE)

assert_is_identical_to_na(x, allow_attributes = FALSE)

assert_is_identical_to_true(x, allow_attributes = FALSE)

assert_all_are_false(x)

assert_any_are_false(x)

assert_all_are_na(x)

assert_any_are_na(x)

assert_all_are_true(x)

assert_any_are_true(x)

assert_all_are_not_false(x)

assert_any_are_not_false(x)

assert_all_are_not_na(x)

assert_any_are_not_na(x)

assert_all_are_not_true(x)

assert_any_are_not_true(x)

is_identical_to_false(x, allow_attributes = FALSE,
  .xname = get_name_in_parent(x))

is_identical_to_na(x, allow_attributes = FALSE,
  .xname = get_name_in_parent(x))

is_identical_to_true(x, allow_attributes = FALSE,
  .xname = get_name_in_parent(x))

is_false(x)

is_na(x)

is_not_na(x)

is_not_false(x)

is_not_true(x)

is_true(x)

Arguments

x
Input to check.
allow_attributes
If TRUE, a scalar value of TRUE with attributes is allowed.
.xname
Not intended to be used directly.

Value

  • The is* functions return TRUE if the input is TRUE/FALSE. The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

See Also

isTRUE.

Examples

Run this code
# Checks against logical values using base::identical
assert_is_identical_to_true(TRUE)
assert_is_identical_to_false(FALSE)
assert_is_identical_to_na(NA)

# Other NA types match
assert_is_identical_to_na(NA_complex_)

# NaN is not NA
dont_stop(assert_is_identical_to_na(NaN))

# For a slightly less strict test, you can ignore attributes
assert_is_identical_to_true(c(truth = TRUE), allow_attributes = TRUE)
assert_is_identical_to_false(matrix(FALSE), allow_attributes = TRUE)
assert_is_identical_to_na(structure(NA, class = "nanana"), allow_attributes = TRUE)

# Vectorized predicates
x <- c(TRUE, FALSE, NA)
is_true(x)
is_false(x)
is_na(x)

# ...and their opposites
is_not_true(x)
is_not_false(x)
is_not_na(x)

# Check that at least one element fits the condition
assert_any_are_true(x)
assert_any_are_false(x)
assert_any_are_na(x)

# These tests should fail:
dont_stop(assert_is_identical_to_true(c(truth = TRUE)))
dont_stop(assert_is_identical_to_false(matrix(FALSE)))
dont_stop(assert_is_identical_to_na(structure(NA, class = "nanana")))
dont_stop(assert_all_are_true(x))
dont_stop(assert_all_are_false(x))
dont_stop(assert_all_are_na(x))

Run the code above in your browser using DataLab