[Rd] invisible functions

Therneau, Terry M., Ph.D. therne@u @ending from m@yo@edu
Wed Oct 17 00:42:00 CEST 2018


The survival package, like many others, has several helper functions that are not declared 
in the namespace, since their only use is to be called by other "main" functions of the 
package.  This works well since the functions in the survival namespace can see them --- 
without ::: arguments --- and others don't.

Until a situation I ran into this week, for which I solicit comments or advice.   The 
concordance function is a new addition, and it has one case where the same underlying 
helper function is called multiple times, with many arguments passed through from the 
parent.  I thought that this would be a good use for the trick we use for model.frame, so 
I have code like this:

concordance.coxph <- function(fit, ..., newdata, group, ymin, ymax,
                                timewt=c("n", "S", "S/G", "n/G", "n/G2"),
                                influence=0, ranks=FALSE, timefix=TRUE) {
     Call <- match.call()
     .
     .
     .
     cargs <- c("ymin", "ymax","influence", "ranks", "timewt", "timefix")
     cfun <- Call[c(1, match(cargs, names(Call), nomatch=0))]
     cfun[[1]] <- quote(cord.work)
     cfun$reverse <- TRUE
     rval <- eval(cfun, parent.frame())

This worked fine in my not-in-a-namespace test bed, but then fails when packaged up for 
real: the code can't find the helper function cord.work!  The rule that survival package 
functions can "see" their undeclared helpers fails.

I got it working by changing parent.frame() to environment(concordance) in the eval() 
call.   Since everything used by cord.work is explicitly passed in its argument list this 
does work.

Comments or suggestions?   (I avoid having survival:: in the survival package because it 
messes up my particular test bed.)

Terry


	[[alternative HTML version deleted]]



More information about the R-devel mailing list