is_named() checks that none of the names are missing or empty (NA or ""). have_name() is a vectorised version of is_named().

is_named(x)

have_name(x)

## Arguments

x A vector to test.

## Value

is_named() is a scalar predicate that returns TRUE or FALSE. have_name() is vectorised and returns a logical vector as long as the input.

## Details

is_named() always returns TRUE for empty vectors because it tests for the property that each element of a vector is named rather than the presence of a names attribute.

## Examples

# is_named() is a scalar predicate about the whole vector of names:
is_named(c(a = 1, b = 2))
#> [1] TRUEis_named(c(a = 1, 2))
#> [1] FALSE
# have_name() is a vectorised predicate
have_name(c(a = 1, b = 2))
#> [1] TRUE TRUEhave_name(c(a = 1, 2))
#> [1]  TRUE FALSE
# Empty and missing names are treated as invalid:
invalid <- set_names(letters[1:5])
names(invalid)[1] <- ""
names(invalid)[3] <- NA

is_named(invalid)
#> [1] FALSEhave_name(invalid)
#> [1] FALSE  TRUE FALSE  TRUE  TRUE
# A data frame normally has valid, unique names
is_named(mtcars)
#> [1] TRUEhave_name(mtcars)
#>  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
# A matrix usually doesn't because the names are stored in a
# different attribute
mat <- matrix(1:4, 2)
colnames(mat) <- c("a", "b")
is_named(mat)
#> [1] FALSEnames(mat)
#> NULL