[Rd] Question about substitute() and function def

Bill Dunlap bill at insightful.com
Thu Sep 14 21:54:34 CEST 2006


On Thu, 14 Sep 2006, Duncan Murdoch wrote:

> I think it's the same reason that this happens:
>
>  > substitute(c( a = 1, b = a), list(a = quote(foo)))
> c(a = 1, b = foo)
>
> The "a" in function(a) is the name of the arg, it's not the arg itself
> (which is missing).  Now a harder question to answer is why this happens:
>
>  > substitute(function(a=a) 1, list(a=quote(foo)))
> function(a = a) 1
>
> I would have expected to get "function(a = foo) 1".

In Splus you do get what you expected.
   > substitute(function(a=a) 1, list(a=quote(foo)))
   function(a = foo)
   1
   > substitute(function(a=func(100))func(a), list(func=quote(myFunction)))
   function(a = myFunction(100))
   myFunction(a)

R's substitute does not appear to go into
the 'formals' of a function definition
when looking for names to replace.

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."




More information about the R-devel mailing list