I went through the same problem and discovery process 2 years ago with the survival package. With pspline() terms the return object from coxph includes a simple 6 line function for enhanced printout, which by default carried along another 30 irrelevant things some of which were huge. I personally think that setting environment(f) <- .Globalenv is the clearest and most simple solution. Note that R does not save the environment of functions defined at the top level; the prior line says to treat your function as "one of those". It works very well as long as your function is an actual function, i.e. It depends only on its input arguments.
\begin {opinion} S started out as a pure functional language. That is, a function depends ONLY on its arguments. Many of the strengths of S/R flow directly from the simplicity and rigor that this gives. There is an adage in programming, going back to at least the earliest Fortran compilers, that all successful languages have a way to break their own rules; and S indeed had some hidden workarounds. Formalizing these non-functional back doors as R has done with environments is a good thing. However, the back doors should be used only with extreme reluctance. I cringe at each new "how to be sneaky" discussion on the mailing lists. The 'solution' is rarely worth the long term price. \end{opinion} Terry Therneau [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel