[R] survival package can't find Ccoxfit6

SeshanV at mskcc.org SeshanV at mskcc.org
Thu Apr 27 16:53:43 CEST 2017

Thank you Drs. Therneau and Murdoch.

"Why not use coxph.fit?" -- My use case scenario is that I needed the Cox model coefficients for resampled data. I was trying to reduce the computational overhead of coxph.fit (since it will repeated a large number of times) by stripping all the parts that I don't need such as sorting of the data prior to coxfit6.c call and Martingale residual and concordance computations after the parameters are estimated. 

Under the R v3.4.0 model one cannot create any modified form of coxph.fit and expect it to work. Worse yet is the following where I copy "coxph.fit" to my workspace as "mycoxph.fit" (works initially because the environment is namespace:survival and fails when environment changed to R_GlobalEnv)

> set.seed(12345)
> x <- rep(0:1, c(20,20))
> y <- cbind(c(-log(runif(20)), -2*log(runif(20))), rep(1,40))
> mycoxph.fit <- coxph.fit
> control <- coxph.control()
> oo1 <- coxph.fit(as.matrix(as.double(x)), y, NULL, NULL, NULL, control, NULL, "efron", NULL)
> oo2 <- mycoxph.fit(as.matrix(as.double(x)), y, NULL, NULL, NULL, control, NULL, "efron", NULL)
> all.equal(oo1, oo2)
[1] TRUE
> environment(mycoxph.fit)
<environment: namespace:survival>
> environment(mycoxph.fit) <- .GlobalEnv
> environment(mycoxph.fit)
<environment: R_GlobalEnv>
> mycoxph.fit(as.matrix(as.double(x)), y, NULL, NULL, NULL, control, NULL, "efron", NULL)
Error in mycoxph.fit(as.matrix(as.double(x)), y, NULL, NULL, NULL, control,  : 
  object 'Ccoxfit6' not found

So the question is can a user create new functions modeled after existing functions os is the new model going to hinder it?


-----Original Message-----
From: Therneau, Terry M., Ph.D. [mailto:therneau at mayo.edu] 
Sent: Thursday, April 27, 2017 8:30 AM
To: R-help
Cc: Duncan Murdoch; Seshan, Venkatraman E./Epidemiology-Biostatistics
Subject: Re: survival package can't find Ccoxfit6

  Let me summarize rather than repeat the entire thread:

An error report from a user (seshan) stumped me, and I asked for help here.

Duncan Murdoch picked up on fine details of the error message, i.e., that the error did NOT come from within the survival package.  That changes the whole tenor of the discussion.

Indeed, the user has their own function "phcoefs" that directly calls one of my internal C 
routines.  As of R 3.4, this can only be done for routines that I explicitly export.   I 
don't export coxfit6.c.

Where to go from here?

1. I'm not against exporting a routine, but I'm not going to do it without a discussion.  
Doing so is more work for me: I'd need to write a test routine in order to ensure long-term reliability of the export, and it ties my hands wrt future changes.  In this partiuclar case, why not use coxph.fit?

2. One of the design goals for the survival package is to make it usable as a component for other's work.  For instance all of the return structures are easily inspected (no S4
classes) and most are carefully documented e.g. help(coxph.object).  The core computations of coxph are split out into separate functions coxph.fit and agreg.fit, so that they can be called directly without the formula and argument checking overhead.  Ditto for survreg, survifit, survdiff and concordance.  Given the number of other packages that depend on survival I have been at least moderately successful at this aim.  (To be honest this is not entirely alturism on my part as it stops the near infinite requests to add one 'just one more thing' to the package.)  This also means I am open to modifying a routine or exporting a call -- if you can make a good argument.

3. I need a good way to document this for the survival package. Yet one more chapter in my
1/2 written book. Someday...

4. Calling another package's C routines is dangerous, and one of the goals of the 3.4 namespace changes was to stop this from happening willy-nilly.  The new error messages 
look like success.   Though it means that I'm getting multiple "not found" emails.

Terry T.


     Please note that this e-mail and any files transmitted from
     Memorial Sloan Kettering Cancer Center may be privileged, confidential,
     and protected from disclosure under applicable law. If the reader of
     this message is not the intended recipient, or an employee or agent
     responsible for delivering this message to the intended recipient,
     you are hereby notified that any reading, dissemination, distribution,
     copying, or other use of this communication or any of its attachments
     is strictly prohibited.  If you have received this communication in
     error, please notify the sender immediately by replying to this message
     and deleting this message, any attachments, and all copies and backups
     from your computer.

More information about the R-help mailing list