On Wed, Apr 11, 2012 at 10:17 PM, Whit Armstrong
<armstrong.whit at gmail.com> wrote:> 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.
>
f <- function(x=x) x^2 is an endless recursion. Try
f <- function(x.=x) { x^2 }
(note the dot)
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com