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

From: Luke Tierney <>
Date: Wed 05 Apr 2006 - 15:42:34 GMT

On Wed, 5 Apr 2006, Prof Brian Ripley wrote:

> 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.

I think the callfun field in the context is intended to contains this and was added with the intent of making things like sys.function more reliable but I'm not sure this was ever fully implemented. Might be worth checking into after 2.3 and modifying Recall to use it.


Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:
Iowa City, IA 52242                 WWW:

______________________________________________ mailing list
Received on Thu Apr 06 02:08:19 2006

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