From ggrothendieck at myway.com  Wed Nov 10 02:53:18 2004
From: ggrothendieck at myway.com (Gabor Grothendieck)
Date: Wed Nov 10 02:53:29 2004
Subject: [Rd] recursive default argument reference
References: <C698D707214E6F4AB39AB7096C3DE5A5750FE8@phost015.EVAFUNDS.intermedia.net>
Message-ID: <loom.20041110T024809-978@post.gmane.org>

Vadim Ogranovich <vograno <at> evafunds.com> writes:

: 
: Hi,
: 
: It seems that a formal function argument can not default to an "outer"
: variable of the same name:
: 
: > x <- "foo"
: > ff <- function(x=x) x
: > ff()
: Error in ff() : recursive default argument reference
: > 
: 
: Is this intentional? Why?
: 

Because then one arg could not safely refer to another. Here
x has y as its default value:

   x <- 10
   y <- 7
   f <- function(x = y, y = 3) print(x)
   f() # prints 3

Note that you could do this:

   x <- "foo"
   ff <- function(x.=x) x.
   ff() # returns "foo"
   ff(x=44) # returns 44
   ff(55) # returns 55

For a real example look at merge.data.frame.


[Rd] recursive default argument reference
Gabor Grothendieck