[R] deferred call

Whit Armstrong armstrong.whit at gmail.com
Thu Apr 12 04:17:35 CEST 2012


I must admit I'm a little ashamed to have been using R for so long,
and still lack a sound understanding of deferred calls, eval, deparse,
substitute, and friends.

I'm attempting to make a deferred call to a function which has default
arguments in the following way:

call.foo <- function(f) {
    x <- f()
}

x <- 1:10
f <- function(x=x) { x^2 }
call.foo(f)

However, I'm getting the error:
Error in x^2 : 'x' is missing

Is there a common R idiom for calling 'formals' on the function, and
then grabbing the named default arguments from the enclosing frame?

I naively thought that since function 'f' was defined w/ a default
argument of 'x' and x is defined in the same envir as the function
itself, that the call would succeed.

-Whit



More information about the R-help mailing list