[Rd] Inconsistencies in missing names of a list?

Bernd Bischl bernd_bischl at gmx.net
Tue Aug 4 15:10:23 CEST 2009


Hi,

I would like to discuss whether the following behaviour in lists is 
indeed intended:

###################################################
 > sessionInfo()
R version 2.10.0 Under development (unstable) (2009-07-21 r48968)
i386-pc-mingw32

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252  [3] 
LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                  [5] 
LC_TIME=German_Germany.1252  
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base 
###################################################

# case 1
x1 <- list(1, 2)
names(x1)[2]
# returns NULL

# case 2
x2 <- list(foo=1, 2)
names(x2)[2]
# returns ""

# case 3
x3 <- list(1, 2)
names(x3)[1] <- "foo"
names(x3)[2]
# returns NA

###################################################

Although I don't find it particularly good that 1) and 2)  behave 
differently, I can very well understand what happens and accept this.

I may also understand (on a technical level) what happens in 3), but I 
find it very disturbing that these lines

x2 <- list(foo=1, 2)
x3 <- list(1, 2)
names(x3)[1] <- "foo"

produce different results.

?names says

" 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."

If it "likely leads to confusion" why does the implementation use it?

Regards,

Bernd Bischl



More information about the R-devel mailing list