From stvjc at channing.harvard.edu  Mon Feb  6 18:04:27 2006
From: stvjc at channing.harvard.edu (Vincent Carey 525-2265)
Date: Mon, 6 Feb 2006 12:04:27 -0500 (EST)
Subject: [Rd] extending "list" in S4: loss of element names
Message-ID: <Pine.GSO.4.58.0602061149260.7709@capecod.bwh.harvard.edu>


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



[Rd] extending "list" in S4: loss of element names
Vincent Carey 525-2265