[R] terms.inner

Thomas Lumley tlumley at u.washington.edu
Tue Sep 5 16:31:39 CEST 2006


On Tue, 5 Sep 2006, Terry Therneau wrote:

> Question:
>  I am trying to impliment a function in R that we use quite regularly in
> Splus, and it fails due to a lack of the "terms.inner" function in R.
> The substitute is?
>
> Part question and part soapbox:
> Why remove terms.inner from R?  It's little used, but rather innocuous.

AFAIK it wasn't removed, it just hasn't ever been implemented. Probably 
no-one in the early years of R tried to port any code that used it -- 
there were a number of functions added back then just because the survival 
package used them, such as subscripting on terms objects.

> Mostly soapbox:
>  I figured it was no big deal, as I originally discovered the use of
> terms.inner from reading the plot.gam function.  So I'd just see what
> plot.gam does in R.
> > plot.gam
> Error: object "plot.gam" not found
>
>  Ok, I know this function has to exist.  I even remember that there is some
> sort of multi-colon secret handshake that will convince R to let you look
> at it, although I don't remember the form.  This Nixonesque passion with
> hiding things is one of the reasons I still prefer Splus.

Perhaps not the best soapbox example. There are at least two gam 
implementations, but they are both in add-on packages. Neither of them 
hides its plot.gam in a namespace, but you do need to install and load the 
package.  You presumably want Trevor Hastie's one, which is in the "gam" 
package, rather than Simon Woods' one in the "mgcv" package.

BTW, termplot() does many of the same things as Hastie's plot.gam(). It is 
also not hidden. If I understand correctly what terms.inner does, 
termplot() uses two functions:
     pf <- envir
     carrier <- function(term) {
         if (length(term) > 1)
             carrier(term[[2]])
         else eval(term, data, enclos = pf)
     }
     carrier.name <- function(term) {
         if (length(term) > 1)
             carrier.name(term[[2]])
         else as.character(term)
     }
to do the job.


 	-thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



More information about the R-help mailing list