names
is a generic accessor function, and names<-
is a
generic replacement function. The default methods get and set
the "names"
attribute of a vector (including a list) or
pairlist.
For an environment
env
, names(env)
gives
the names of the corresponding list, i.e.,
names(as.list(env, all.names = TRUE))
which are also given by
ls(env, all.names = TRUE, sorted = FALSE)
. If the
environment is used as a hash table, names(env)
are its
“keys”.
If value
is shorter than x
, it is extended by character
NA
s to the length of x
.
It is possible to update just part of the names attribute via the
general rules: see the examples. This works because the expression
there is evaluated as z <- "names<-"(z, "[<-"(names(z), 3, "c2"))
.
The name ""
is special: it is used to indicate that there is no
name associated with an element of a (atomic or generic) vector.
Subscripting by ""
will match nothing (not even elements which
have no name).
A name can be character NA
, but such a name will never be
matched and is likely to lead to confusion.
Both are primitive functions.