[Rd] Inconsistency with component names

Duncan Murdoch dmurdoch at pair.com
Thu Mar 4 14:29:17 MET 2004


Working in r-devel, we're not allowed to use a list component name of
"":

> list(a = 1, "" = 2)
Error: attempt to use zero-length variable name

However, that's what gets reported to us if we create a list with no
name:

> x <- list(a = 1, 2)
> names(x)
[1] "a" "" 

The names<- function apparently doesn't check for the error:

> x <- list(1, 2)
> names(x) <- c("a", "")
> names(x)
[1] "a" "" 

and it allows all names to be blank:

> names(x) <- c("", "")
> names(x)
[1] "" ""

However, if we do it with a piece of language, things are different:

> x <- quote(list(1,2))
> x
list(1, 2)
> mode(x)
[1] "call"
> names(x)
NULL
> names(x) <- c("", "a", "")
> x
list(a = 1, 2)
> names(x) <- c("", "", "")
> x
list(1, 2)
> names(x)
NULL

I think the behaviour should be consistent between lists and call
objects; if the behaviour for calls followed the behaviour for lists,
it would let me save a line (if (is.null(names(x)) .... ) in the
margins function.

Even though they print the same way, names of c("", "", "") are
different from no names at all.

Duncan Murdoch



More information about the R-devel mailing list