Re: [Rd] and Recall() (Was: Re: Return function from function and Recall())

From: Prof Brian Ripley <>
Date: Wed 05 Apr 2006 - 12:32:19 GMT

On Wed, 5 Apr 2006, Henrik Bengtsson wrote:

> On 4/5/06, Prof Brian Ripley <> wrote:
>> On Wed, 5 Apr 2006, Henrik Bengtsson wrote:
>>> Hi,
>>> forget about the below details. It is not related to the fact that
>>> the function is returned from a function. Sorry about that. I've
>>> been troubleshooting soo much I've been shoting over the target. Here
>>> is a much smaller reproducible example:
>>> x <- 1:10
>>> y <- 1:10 + rnorm(length(x))
>>> sp <- smooth.spline(x=x, y=y)
>>> ypred <- predict(sp$fit, x)
>>> # [1] 2.325181 2.756166 ...
>>> ypred2 <- predict(sp$fit, c(0,x))
>>> # Error in Recall(object, xrange) : couldn't find
>>> # function ""
>> 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 for now.
> More troubleshooting shows that by dispatching directly on 'sp' and
> not 'sp$fit' works. The reason that I do not want to do this is
> related to my questions yesterday that I want to keep the memory usage
> down and 'sp' hold quite some extra data even with

Ahah! So you are not using this as intended, and I had not spotted this. Now I understand: you are calling predict, which finds via method registration, and dispatches it in the environment used to call predict, .GlobalEnv, where of course it is not visible. Then Recall uses that environment, but attempts to call the method directly.

If you call this as intended, predict is called from the body of predict.smooth.spline where is visible.

I am afraid that you should not be expecting to be able to subvert things this way.


Now, I was a little surprised that Recall() needed to do a lookup, but R's context only contains the name of the called function and not (a pointer to) the function.

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
Received on Wed Apr 05 23:03:15 2006

This archive was generated by hypermail 2.1.8 : Wed 05 Apr 2006 - 18:17:48 GMT