Skip to content
Prev 20094 / 63421 Next

predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())

On Wed, 5 Apr 2006, Henrik Bengtsson wrote:

            
It seems Recall is not searching (via findFun) from the right environment, 
but at a quick glance it is not obvious to me why.
You can replace Recall by predict.smooth.spline.fit for now.

As for
it is rather tricky.  page() takes a name aka symbol as its argument (and 
is thereby S-compatible), and also works with a bare character string 
(undocumented).  What you have here is a call that does not even return a 
function.  It is more reasonable that stats:::predict.smooth.spline.fit 
should work, and it is also a call.  I have in the past thought about 
special-casing that, but it is a valid name (you would have to back-quote 
it, but it does work).  So one possible way out would be to use get() on a 
name and evaluate calls, e.g.

page <- function(x, method = c("dput", "print"), ...)
{
     subx <- substitute(x)
     have_object <- FALSE
     if(is.call(subx)) {
         object <- x
         have_object <- TRUE
         subx <- deparse(subx)
     } else {
         if(is.character(x)) subx <- x
         else if(is.name(subx)) subx <- deparse(subx)
         if (!is.character(subx) || length(subx) != 1)
             stop("'page' requires a name, call or character string")
         parent <- parent.frame()
         if(exists(subx, envir = parent, inherits=TRUE)) {
             object <- get(subx, envir = parent, inherits=TRUE)
             have_object <- TRUE
         }
     }
     if(have_object) {
         method <- match.arg(method)
         file <- tempfile("Rpage.")
         if(method == "dput")
             dput(object, file)
         else {
             sink(file)
             print(object)
             sink()
         }
 	file.show(file, title = subx, delete.file = TRUE, ...)
     } else
 	stop(gettextf("no object named '%s' to show", subx), domain = NA)
}

which also allows 1-element character vectors (and I am not entirely sure 
we want that).