From bill at insightful.com  Thu Sep 14 21:54:34 2006
From: bill at insightful.com (Bill Dunlap)
Date: Thu, 14 Sep 2006 12:54:34 -0700 (PDT)
Subject: [Rd] Question about substitute() and function def
In-Reply-To: <4509AFA4.6010203@stats.uwo.ca>
References: <m2d59y8e7o.fsf@ziti.fhcrc.org> <4509AFA4.6010203@stats.uwo.ca>
Message-ID: <Pine.GSO.4.56.0609141248020.2611@durian.statsci.com>

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




[Rd] Question about substitute() and function def
Bill Dunlap