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

From: Vincent Carey 525-2265 <stvjc_at_channing.harvard.edu>
Date: Mon 06 Feb 2006 - 17:04:27 GMT

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



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Feb 07 04:14:06 2006

This archive was generated by hypermail 2.1.8 : Tue 07 Feb 2006 - 01:51:58 GMT