[Rd] extending "list" in S4: loss of element names

Vincent Carey 525-2265 stvjc at channing.harvard.edu
Mon Feb 6 18:04:27 CET 2006


using R 2.3 of 1/31/06

> new("list")
list()
> new("list", list(a=1))
$a
[1] 1

> setClass("listlike", contains="list")
[1] "listlike"
> new("listlike", list(a=1))
An object of class "listlike"
[[1]]
[1] 1

Why does the list in the second construction lose
the element name?  A workaround is to endow the
listlike class with a names slot, but it would
be nice for the names to be propagated from the
data to the object.

Loss of names in a numeric construction does
not require extension:
> new("numeric", c(a=1))
[1] 1

But coercion can allow names to persist.
> as(c(a=1), "numeric")
a
1



More information about the R-devel mailing list