[Rd] Baffled with as.matrix
therneau at mayo.edu
Fri Nov 30 13:53:36 CET 2012
I'm puzzled by as.matrix. It appears to work differently for Surv objects.
Here is a session from my computer:
tmt% R --vanilla
Loading required package: splines
> ytest <- Surv(1:3, c(1,0,1))
> attr(ytest, 'type')
> attr(as.matrix(ytest), 'type')
> y2 <- ytest
> class(y2) <- "charlie"
> as.matrix.charlie <- survival:::as.matrix.Surv
> attr(y2, 'type')
> attr(as.matrix(y2), 'type')
y <- unclass(x)
attr(y, "type") <- NULL
It appears that Surv objects are being processed by as.matrix.default, but "charlie"
objects by the
actual method. One more verification:
> attr(survival:::as.matrix.Surv(ytest), 'type')
> attr(as.matrix.default(y2), 'type')
Context: In testing the next survival release (2.37), it has lost this "special"
behavior. One package that depends on survival expects this behavior and thus fails. I'm
at a loss to figure out how my package got this attribute in the first place, or how it
lost it. Can anyone shed light?
PS I'm on vacation for the next few days so will be intermittent with email. (Off to see
my first grandchild!)
R version 2.15.2 (2012-10-26)
Platform: i686-pc-linux-gnu (32-bit)
 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
 LC_TIME=en_US.UTF-8 LC_COLLATE=C
 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
 LC_PAPER=C LC_NAME=C
 LC_ADDRESS=C LC_TELEPHONE=C
 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
 splines stats graphics grDevices utils datasets methods
other attached packages:
More information about the R-devel