[Rd] as(object,"list") as(object,"matrix") differences?

From: Wolski <wolski_at_molgen.mpg.de>
Date: Wed 08 Sep 2004 - 00:17:21 EST


Hello!

as(object,"list") and as(object,"matrix") behave quite differently if it comes to their attributes. I define two classes. One of them "contains" a "list" the other a "matrix" setClass("myclass"
,representation(info="character")
,contains="matrix"
)
setClass("mylist"
,representation(info="character")
,contains="list"
)

#init
dd<-matrix(1:6,nrow=2)
rownames(dd)<-c("a","b")
tt<-new("myclass",dd)

tmp<-vector("list",4)
names(tmp)<-1:4
ll <- new("mylist",tmp,info="foo")

rownames(tt)
[1] "a" "b"
> rownames(as(tt,"matrix"))

[1] "a" "b"

> names(ll)

[1] "1" "2" "3" "4"
> names(as(ll,"list"))


NULL
#but
names(ll@.Data)
The difference in behaviour to which i would like to point your attention is that as(object,"matrix") preserves the "dimnames" but at the same time as(object,"list") drops the "names" attribute.

Is it recomended not to use "contains" with old style classes? Are there plans to provide standarized S4 versions/wrappers for list, matrix etc... classes?

/E

PS.
R : Copyright 2004, The R Foundation for Statistical Computing Version 1.9.1 Patched (2004-08-30), ISBN 3-900051-00-3



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed Sep 08 00:22:41 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:00:05 EST