is_atomic: Is the input atomic/recursive/vector?

View source: R/is-atomic-recursive-vector.R

assert_is_atomicR Documentation

Is the input atomic/recursive/vector?

Description

Checks to see if the input is a type that is atomic/recursive/vector.

Usage

assert_is_atomic(x, severity = getOption("assertive.severity", "stop"))

assert_is_nested(x, severity = getOption("assertive.severity", "stop"))

assert_is_non_nested(x, severity = getOption("assertive.severity", "stop"))

assert_is_recursive(x, severity = getOption("assertive.severity", "stop"))

assert_is_vector(x, severity = getOption("assertive.severity", "stop"))

is_atomic(x, .xname = get_name_in_parent(x))

is_nested(x, .xname = get_name_in_parent(x))

is_non_nested(x, .xname = get_name_in_parent(x))

is_recursive(x, .xname = get_name_in_parent(x))

is_vector(x, .xname = get_name_in_parent(x))

Arguments

x

Input to check.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

.xname

Not intended to be used directly.

Value

is_atomic, is_recursive and is_vector wrap is.atomic, is.recursive and is.vector respectively, providing more information on failure. is_nested checks for recursive objects where at least one element is also recursive. is_non_nested returns TRUE for atomic objects and recursive objects where no elements are recursive. The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

See Also

is.atomic and is.vector.

Examples

atomic_types <- list(
  logical(),
  integer(),
  numeric(), 
  complex(),
  character(), 
  raw(),
  matrix(), 
  array(),
  factor(),
  NULL
)
for(var in atomic_types) assert_is_atomic(var)

recursive_types <- list(
  list(), 
  expression(),
  data.frame(), 
  y ~ x,
  function(){},
  call("sin", "pi")
)
for(var in recursive_types) assert_is_recursive(var)

# Names are neither atomic nor recursive
a_name <- as.name("x")
is_atomic(a_name)
is_recursive(a_name)

vector_types <- c(
  atomic_types[1:6], 
  recursive_types[1:2]
)
for(var in vector_types) assert_is_vector(var)

# Nested objects are recursive and have at least one recursive element
nested_list <- list(a = 1, b = list(2:3))
assert_is_nested(nested_list)
for(elt in nested_list) assert_is_non_nested(elt)

assertive.properties documentation built on April 21, 2022, 5:13 p.m.