[R] Surv object in data.frame and Design package

Heinz Tuechler tuechler at gmx.at
Thu Mar 16 23:53:12 CET 2006


At 11:13 16.03.2006 -0800, Thomas Lumley wrote:
>On Thu, 16 Mar 2006, Heinz Tuechler wrote:
>
>> Dear All,
>>
>> there seems to be some strange influence of the Design package on
>> data.frame. If I build a data.frame containing a Surv object without
>> loading the package Design, the data frame is usable to coxph. If instead I
>> just load Design and build a data.frame afterwards, the naming of the Surv
>> object is different and it does not work with coxph.
>> (In my real application I loaded Design to use the ie.setup function.)
>> Even if I detach Design I cannot build a data.frame as before loading
>> Design. If I include the Surv object with the I() function it seems to
>> work, but then there appeare the problems discussed in the posting from
>> yesterday "Surv object in data.frame".
>> The problem is solvable, but I was surprised of the unexpected
>> difficulties, especially that detaching Design did not solve the problem.
>>
>> Is it wrong to expect that R works after detaching a package as before
>> loading it?
>
>It's not as strange as all that. The Design package requires the Hmisc 
>package, which you did not detach.  Hmisc contains an implementation of 
>as.data.frame.Surv that doesn't work with data.frame()
>
>Unfortunately the Hmisc implementation overrides the survival one, 
>irrespective of the order in which the packages are loaded (at least from 
>the viewpoint of getS3method()).
>
>For code internal to the survival package the namespace system ensures 
>that survival:::as.data.frame.Surv is called, but data.frame() is not part 
>of the survival package and sees the Hmisc version.
>
>I would have expected that S3 methods registered in NAMESPACE would 
>override those based on the function name, but it seems to be the other 
>way around.
>
>
>Also, when you detached "Design" you also detached "survival". If "Design" 
>rather than "Hmisc" had been the source of the problem this still wouldn't 
>have worked as no as.data.frame method for Surv objects would have been 
>available.
>
>
> 	-thomas
>
Thanks a lot for this explanation. I tried all this also with Hmisc and
woundered, why the effect of Hmisc was "reversible" by detaching it and
that of Design was not. Now I see.

Thanks again

Heinz




More information about the R-help mailing list