assertions | R Documentation |
assert_that
We provide additional assertion functions which can be used together with
assertthat::assert_that()
.
We provide additional assertion functions which can be used together with
the checkmate
functions. These are described in individual help pages
linked below.
is_class(x, class2)
is_hermes_data(x)
is_counts_vector(x)
is_list_with(x, elements)
one_provided(one, two)
is_constant(x)
x |
an object to check. |
class2 |
( |
elements |
( |
one |
first input. |
two |
second input. |
Depending on the function prefix.
assert_
functions return the object invisibly if successful, and otherwise
throw an error message.
check_
functions return TRUE
if successful, otherwise a string with the
error message.
test_
functions just return TRUE
or FALSE
.
is_class()
: checks the class.
is_hermes_data()
: checks whether x
is an AnyHermesData
object.
is_counts_vector()
: checks for a vector of counts (positive integers).
is_list_with()
: checks for a list containing elements.
one_provided()
: checks that exactly one of the two inputs one
, two
is not NULL
.
is_constant()
: checks whether the vector x
is constant (only supports numeric
, factor
,
character
, logical
). NA
s are removed first.
assert_proportion()
# Assert a general class.
a <- 5
is_class(a, "character")
# Assert a `AnyHermesData` object.
is_hermes_data(hermes_data)
is_hermes_data(42)
# Assert a counts vector.
a <- 5L
is_counts_vector(a)
# Assert a list containing certain elements.
b <- list(a = 5, b = 3)
is_list_with(b, c("a", "c"))
is_list_with(b, c("a", "b"))
# Assert that exactly one of two arguments is provided.
a <- 10
b <- 10
one_provided(a, b)
one_provided(a, NULL)
# Assert a constant vector.
is_constant(c(1, 2))
is_constant(c(NA, 1))
is_constant(c("a", "a"))
is_constant(factor(c("a", "a")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.