Hi Vince --
Not a solution, but a little understanding and a workaround. With C1,
what happens is that the 'names' attribute of ll gets transfered to
the 'names' attribute of the S4 instance.
Method Definition:
function (from, to, value)
{
.value <- as(from, "C1")
as(.value, "list") <- value
value <- .value
{
for (what in ".Data") slot(from, what) <- slot(value,
what)
from
}
}
Signatures:
from to
target "C2" "list"
defined "C2" "list"
C2 gets coerced to its super class, C1. C1 is then assigned the list,
including attributes. The bug enters in the 'for (what in ".Data")',
where the slots of .Data from C1, but not the attributes, are
copied.
The code chunk above is generated in methods:::.simpleReplaceExpr;
naively copying attributes from 'value' to 'from' does not work, as
attributes on 'from' include it's class.
A workaround would be to define an appropriate setAs
setClass("C1", contains="list")
[1] "C1"
setClass("C2", contains="C1")
[1] "C2"
setAs("C2", "list",
+ def=function(from) stop('your def here'),
+ replace=function(from, to, value) {
+ from at .Data <- value
+ from
+ })
[1] "coerce<-"
R version 2.6.0 Under development (unstable) (2007-05-11 r41535)
powerpc-apple-darwin8.9.0
locale:
C
attached base packages:
[1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
[7] "base"