Skip to content
Prev 47558 / 63424 Next

package NAMESPACE question

An example of this is found in the coxph function in the survival library.  Look at it for 
guideance.
Within a coxph formula the expression "tt(x)" means to use a time transform on variable x. 
  The tt function is a fake, defined as tt <- function(x) x, whose only purpose is to 
allow the user to mark a variable for special treatment while staying inside the syntax 
rules of formulas.
   tt is not exported, because no one would ever want to use it.  It is documented within 
the coxph manual pages.  I did export it at one time, for exactly the reasons and error 
message detailed by Axel.  I recieved a request to cease doing so because of package 
issues --- someone had a package with a real and useful tt function, which would be masked 
if "require(survival)" ever occured, placing my library with its worthless function before 
his on the search path.  Enough things depend on the survival package that this was making 
his package's results unpredictable.

   The root issue is that formulas are often counterintuitive.  R treats them as though 
they were a function, but with a special evaluation context.  Thus even though a formula 
is evaluated within the coxph function, components of the formula are not "in" the 
survival namespace and so can't see non-exported functions in that namespace.   If you 
found this confusing be assured that you are not alone.

Terry Therneau
On 01/29/2014 05:00 AM, r-devel-request at r-project.org wrote: