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? Comments? Thanks Heinz T?chler ## example starttime <- c(0, 0, 1.5, 0, 2.5) stoptime <- c(1, 1.5, 2, 2.5, 3) event <- c(1, 0, 1, 0, 0) ie.status <- c(0, 0, 1, 0, 1) library(survival) survobj <- Surv(starttime, stoptime, event) df.nodesign <- data.frame(survobj, ie.status) # build df without loading Design df.nodesign library(Design) df.design <- data.frame(survobj, ie.status) # build df after loading Design df.design all.equal(df.nodesign, df.design) detach(package:Design) detach(package:survival) df.afterdesign <- data.frame(survobj, ie.status) # building df after detaching Design df.afterdesign library(survival) rm(survobj, ie.status) coxph(survobj~ie.status, data=df.nodesign) # works coxph(survobj~ie.status, data=df.design) # doesn't works coxph(survobj~ie.status, data=df.afterdesign) # doesn't works Windows98 SE Version 2.2.0 Patched (2005-10-31 r36100)
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
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