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, = FALSE,
  info = NULL, label = NULL)



object to test


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 (useful when writing tests in loops).


object label. When NULL, computed from deparsed object.


Other arguments passed on to has_names().

See also

Other expectations: comparison-expectations, equality-expectations, expect_length, expect_match, inheritance-expectations, logical-expectations, output-expectations


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, = TRUE) # Can also check for the absence of names with NULL z <- 1:4 expect_named(z, NULL)