
Last chance! 50% off unlimited learning
Sale ends in
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
).
expect_named(object, expected, ignore.order = FALSE,
ignore.case = FALSE, info = NULL, label = NULL)
Object to test.
Supports limited unquoting to make it easier to generate readable failures within a function or for loop. See quasi_label for more details.
Character vector of expected names. Leave missing to
match any names. Use NULL
to check for absence of names.
If TRUE
, sorts names before comparing to
ignore the effect of order.
If TRUE
, lowercases all names to ignore the
effect of case.
Extra information to be included in the message. This argument is soft-deprecated and should not be used in new code. Instead see alternatives in quasi_label.
Used to customise failure messages. For expert use only.
Other arguments passed on to has_names()
.
Other expectations: comparison-expectations
,
equality-expectations
,
expect_error
, expect_length
,
expect_match
, expect_message
,
expect_null
, expect_output
,
expect_silent
,
inheritance-expectations
,
logical-expectations
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab