[Rd] Baffled with as.matrix

From: Terry Therneau <therneau_at_mayo.edu>
Date: Fri, 30 Nov 2012 06:53:36 -0600


I'm puzzled by as.matrix. It appears to work differently for Surv objects. Here is a session from my computer:

ink1">tmt% R --vanilla
> library(survival)

Loading required package: splines
> ytest <- Surv(1:3, c(1,0,1))
> is.matrix(ytest)
>[1] TRUE

> attr(ytest, 'type')

[1] "right"
> attr(as.matrix(ytest), 'type')

[1] "right"
>
ink2">> y2 <- ytest
> class(y2) <- "charlie"
> as.matrix.charlie <- survival:::as.matrix.Surv
>="2386qlink3"> name="2386qlink3"><a name="2386qlink3">ame="2386qlink3">name="2386qlink3"> name="2386qlink3"><a name="2386qlin2386qlink3">k3">ame="2386qlink3">nname="2386qlink3">ame= name="2386qlink3">"238<a name="2386qlink3">6qliame="2386qlink3"qlink3">>nk3ame="2386qlink3">" name="2386qlink3">name name="2386qlink3">="23<a name="2386qlink3">86qlame="2386qlink3"qlink3">>inkame="2386qlink3">3 name="2386qlink3">name name="2386qlink3">="23<a name="2386qlink3">86qlame="2386qlink3">ink2386qlink3">3ame="2386qlink3">namename="2386qlink3">="23 name="2386qlink3">86ql<a name="2386qlink3">ink3ame="2386qlink3">">">name="23<a name="2386qlink3">86qlame="2386qlink3">ink3name="2386qlink3">">">> attr(y2, 'type')

[1] "right"
> attr(as.matrix(y2), 'type')

NULL
> survival:::as.matrix.Surv

function (x)
{

     y <- unclass(x)
     attr(y, "type") <- NULL
     y

}
<bytecode: 0x91c1610>
<environment: namespace:survival>

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')
NULL

> attr(as.matrix.default(y2), 'type')

[1] "right"

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?

Terry Therneau

PS I'm on vacation for the next few days so will be intermittent with email. (Off to see my first grandchild!)


> sessionInfo()

R version 2.15.2 (2012-10-26)
Platform: i686-pc-linux-gnu (32-bit)

locale:

  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C
  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=C                 LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] splines stats graphics grDevices utils datasets methods [8] base

other attached packages:
[1] survival_2.36-14



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 30 Nov 2012 - 12:56:57 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 01 Dec 2012 - 04:42:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive