| has_names {testthat} | R Documentation |
You can either check for the presence of names (leaving expected
blank), specific names (by suppling a vector of names), or absence of
names (with NULL).
has_names(expected, ignore.order = FALSE, ignore.case = FALSE) expect_named(object, expected, ..., info = NULL, label = NULL)
expected |
Character vector of expected names. Leave missing to
match any names. Use |
ignore.order |
If |
ignore.case |
If |
object |
object to test |
... |
Other arguments passed onto |
info |
extra information to be included in the message (useful when writing tests in loops). |
label |
object label. When |
Other expectations: equals_reference,
expect_equal_to_reference;
equals, expect_equal;
expect-compare,
expect_less_than,
expect_more_than,
is_less_than, is_more_than;
expect_equivalent,
is_equivalent_to;
expect_error, throws_error;
expect_false, expect_true,
is_false, is_true;
expect_identical,
is_identical_to; expect_is,
is_a; expect_match,
matches; expect_message,
shows_message; expect_null,
is_null; expect_output,
prints_text; expect_warning,
gives_warning;
takes_less_than
x <- c(a = 1, b = 2, c = 3)
expect_named(x)
expect_named(x, c("a", "b", "c"))
# Use options to control sensitivity
expect_named(x, c("B", "C", "A"), ignore.order = TRUE, ignore.case = TRUE)
# Can also check for the absence of names with NULL
z <- 1:4
expect_named(z, NULL)