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

Wolski wolski at molgen.mpg.de
Tue Sep 7 16:17:21 CEST 2004


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



More information about the R-devel mailing list