Skip to content

survival package can't find Ccoxfit6

8 messages · Terry Therneau, SeshanV at mskcc.org, Duncan Murdoch +1 more

#
A user contacted me directly about this, I answered with my best understanding of the 
recent R-help discussion of the issue, and their response to my response shows that I'm 
not quite right.

I am emphatically not an MS Windows user so am asking for help -- which I will cut/paste 
to this user and to the next dozen who will invariably contact me directly.

Thanks,
   Terry Therneau



-------- Forwarded Message --------
Subject: RE: survival package
Date: Wed, 26 Apr 2017 18:05:30 +0000
From: SeshanV at mskcc.org
To: Therneau, Terry M., Ph.D. <therneau at mayo.edu>

Thank you for the quick response. The session info command for v3.4.0 does in fact report 
survival_2.41-3. Furthermore, while both v3.3.1 and v3.40 are on the same computer the 
library paths do not have any directory in common:
[1] "C:/Program Files/R/R-3.4.0/library"
and
[1] "C:/Program Files/R/R-3.3.1/library"
Thanks,
Venkat


-----Original Message-----
From: Therneau, Terry M., Ph.D. [mailto:therneau at mayo.edu] Sent: Wednesday, April 26, 2017 
1:42 PM
To: Seshan, Venkatraman E./Epidemiology-Biostatistics
Subject: Re: survival package

This has been discussed in R-help by multiple people.  You have a pre-3.4 version of the 
survival package somewhere on your search path, and the method for resolving .C calls has 
changed.   The sessionInfo command should report survival version 2.41-3.

Terry T.
On 04/26/2017 12:17 PM, SeshanV at mskcc.org wrote:
=====================================================================

      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.
#
On 26/04/2017 2:51 PM, Therneau, Terry M., Ph.D. wrote:
As far as I can see, that line doesn't appear in the current survival 
source code, it's from some earlier version of the package.  The current 
one has

coxfit <- .Call(Ccoxfit6,
                      as.integer(maxiter),
                      stime,
                      sstat,
                      x[sorted,],
                      as.double(offset[sorted]),
                      weights,
                      newstrat,
                      as.integer(method=="efron"),
                      as.double(control$eps),
                      as.double(control$toler.chol),
                      as.vector(init),
                      as.integer(1))  # internally rescale

There are several differences, the one leading to the error being the 
change from "Ccoxfit6" in quotes, to Ccoxfit6 not in quotes.  That 
corresponds to the difference between a registered symbol and an 
unregistered one.

Without seeing the code that led to the error message I can't really say 
how the error came about.  There are a few ways:

- The user has a copy of the coxph.fit function from an older version of 
survival saved in their workspace, and are using that one instead of the 
current one.

- Some part of your code returns functions, and one of those is making 
this call based on an object produced in an earlier version of survival.

- There are really two versions of survival on the search path (or 
perhaps copied bits of one), and this call isn't in survival 2.41-3 at all.

Duncan Murdoch
#
Attaching the code that generates the error. The function phcoefs in the attached was modeled after coxph.fit from which all the preprocessing has been stripped so that just coxfit6 (C code) can be called to estimate the coefficients.
Error in .Call("Ccoxfit6", as.integer(control$iter.max), stime, as.integer(sstat),  : 
  "Ccoxfit6" not available for .Call() for package "survival"

Same file with the quotes surrounding "Ccoxfit6" removed
Error in phcoefs(stim[ii], sts[ii], as.matrix(as.double(cvt[ii])), oo$coefficients,  : 
  object 'Ccoxfit6' not found
I can confirm that this error occurs in linux (Ubuntu 14.0.4.5) as well.

Thanks,
Venkat

-----Original Message-----
From: Duncan Murdoch [mailto:murdoch.duncan at gmail.com] 
Sent: Wednesday, April 26, 2017 4:18 PM
To: Therneau, Terry M., Ph.D.; R-help
Cc: Seshan, Venkatraman E./Epidemiology-Biostatistics
Subject: Re: [R] survival package can't find Ccoxfit6
On 26/04/2017 2:51 PM, Therneau, Terry M., Ph.D. wrote:
As far as I can see, that line doesn't appear in the current survival source code, it's from some earlier version of the package.  The current one has

coxfit <- .Call(Ccoxfit6,
                      as.integer(maxiter),
                      stime,
                      sstat,
                      x[sorted,],
                      as.double(offset[sorted]),
                      weights,
                      newstrat,
                      as.integer(method=="efron"),
                      as.double(control$eps),
                      as.double(control$toler.chol),
                      as.vector(init),
                      as.integer(1))  # internally rescale

There are several differences, the one leading to the error being the change from "Ccoxfit6" in quotes, to Ccoxfit6 not in quotes.  That corresponds to the difference between a registered symbol and an unregistered one.

Without seeing the code that led to the error message I can't really say how the error came about.  There are a few ways:

- The user has a copy of the coxph.fit function from an older version of survival saved in their workspace, and are using that one instead of the current one.

- Some part of your code returns functions, and one of those is making this call based on an object produced in an earlier version of survival.

- There are really two versions of survival on the search path (or perhaps copied bits of one), and this call isn't in survival 2.41-3 at all.

Duncan Murdoch
=====================================================================

     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.
#
Thanks to Henrik Bengtsson I found a work around which is to use environment(phcoefs) <- asNamespace("survival")

It seems like the symbols that are accessed using .Call are not accessible from outside the package that defines it.
Error in phcoefs(stim[ii], sts[ii], as.matrix(as.double(cvt[ii])), oo$coefficients,  : 
  object 'Ccoxfit6' not found
[1] -0.4838181

Venkat
#
On 26/04/2017 5:20 PM, SeshanV at mskcc.org wrote:
That's misuse of the package.  As far as I know, the Ccoxfit6 function 
has never been exported from the survival package.  Using unexported 
internals from a package is very dangerous and likely to lead to errors. 
  (As I pointed out, there were other changes to the call besides the 
use of "Ccoxfit6" versus Ccoxfit6.

Duncan Murdoch
#
On 26/04/2017 7:40 PM, SeshanV at mskcc.org wrote:
If it was intended for that function to be called by others, it would 
have been exported, and you could have called it.  It wasn't exported, 
so Dr. Therneau may decide to change its meaning tomorrow, and your code 
will break.  It will be your own fault.

If you don't like the way coxph.fit was written, you should copy all of 
it (including the Ccoxfit6 code), not just part.  Or better:  work with 
Dr. Therneau to improve it for everyone.

Duncan Murdoch
1 day later
#
On 2017-04-26 22:17, Duncan Murdoch wrote:

            
I think it's worthwhile to point out that non-exported symbols are 
available using ':::'.  See WRE Section 5.4.

So, after fixing the argument list, just use '.Call(survival:::Ccoxfit6, 
<args>)' instead of '.Call("Ccoxfit6", <args>, PACKAGE = "survival")'.


Henric Winell
#
On 28/04/2017 5:37 PM, Henric Winell wrote:
Yes, and in another section it says "Using foo:::f instead of foo::f 
allows access to unexported objects. This is generally not recommended, 
as the semantics of unexported objects may be changed by the package 
author in routine maintenance."

Duncan Murdoch