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.
Usage
is_class(x, class2)
is_hermes_data(x)
is_counts_vector(x)
is_list_with(x, elements)
one_provided(one, two)
is_constant(x)Value
Depending on the function prefix.
assert_functions return the object invisibly if successful, and otherwise throw an error message.check_functions returnTRUEif successful, otherwise a string with the error message.test_functions just returnTRUEorFALSE.
Functions
is_class(): checks the class.is_hermes_data(): checks whetherxis anAnyHermesDataobject.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 inputsone,twois notNULL.is_constant(): checks whether the vectorxis constant (only supportsnumeric,factor,character,logical).NAs are removed first.
Examples
# Assert a general class.
a <- 5
is_class(a, "character")
#> [1] FALSE
# Assert a `AnyHermesData` object.
is_hermes_data(hermes_data)
#> [1] TRUE
is_hermes_data(42)
#> [1] FALSE
# Assert a counts vector.
a <- 5L
is_counts_vector(a)
#> [1] TRUE
# Assert a list containing certain elements.
b <- list(a = 5, b = 3)
is_list_with(b, c("a", "c"))
#> [1] FALSE
is_list_with(b, c("a", "b"))
#> [1] TRUE
# Assert that exactly one of two arguments is provided.
a <- 10
b <- 10
one_provided(a, b)
#> [1] FALSE
one_provided(a, NULL)
#> [1] TRUE
# Assert a constant vector.
is_constant(c(1, 2))
#> [1] FALSE
is_constant(c(NA, 1))
#> [1] TRUE
is_constant(c("a", "a"))
#> [1] TRUE
is_constant(factor(c("a", "a")))
#> [1] TRUE
