From wolski at molgen.mpg.de  Mon Feb  2 16:47:54 2004
From: wolski at molgen.mpg.de (wolski)
Date: Mon Feb  2 16:49:28 2004
Subject: [Rd] Wondering about behavior of function as? methods package
Message-ID: <200402021647540129.016EE2AB@harry.molgen.mpg.de>

Hi!

I wondering about the behavior of the 'as'  function.

After reading the following sentences:

?as:
    Returns the version of this object coerced to be the given Class.
and page 285 of programming with data:
"When a class extends another class, a call to as on the ...
Specially page 292
"If tx is an object of a class that extends matrix,
as(tx,"matrix")
extracts the portion of its representation forming the included matrix object."

I would expect that as(tmp,"list") in the example below will extract the list part of trackList together with the names attributes of the list.

setClass("trackList"
         ,representation(info="character")
         ,contains="list")

tmp<-new("trackList",list(a=c(1,1),b=c(2,3,4),d=c("u","v","w")))

 as(tmp,"list")
[[1]]
[1] 1 1

[[2]]
[1] 2 3 4

[[3]]
[1] "u" "v" "w"

Where the names attributes are gone?

On the other hand a call to as(tm,"matrix") as in the next example keeps the names attribute of the matrix.

setClass("trackMatrix"
         ,representation(info="character")
         ,contains="matrix")
tmp<-matrix(1:9,3)
rownames(tmp)<-c("a","b","c")
colnames(tmp)<-c(1:3)
tm<-new("trackMatrix",tmp)
as(tm,"matrix")

Is this behaviour intended (if so why) or is it a bug?

Sincerely
Eryk


[Rd] Wondering about behavior of function as? methods package
wolski