Re: [Rd] Question about substitute() and function def

From: Robert Gentleman <rgentlem_at_fhcrc.org>
Date: Thu 14 Sep 2006 - 19:49:01 GMT

Duncan Murdoch wrote:
> On 9/14/2006 3:01 PM, Seth Falcon wrote:

>> Hi,
>>
>> Can someone help me understand why
>>
>>   substitute(function(a) a + 1, list(a=quote(foo)))
>>
>> gives
>>
>>   function(a) foo + 1
>>
>> and not
>>
>>   function(foo) foo + 1
>>
>> The man page leads me to believe this is related to lazy evaluation of
>> function arguments, but I'm not getting the big picture.

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

yes, but the logic seems to be broken. In Seth's case there seems to be no way to use substitute to globally change an argument and all instances throughout a function, which seems like a task that would be useful.

even here, I would have expected all instances of a to change, not some

> (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

   a bug for sure

> I would have expected to get "function(a = foo) 1".
>
> Duncan Murdoch
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-7700
rgentlem@fhcrc.org

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri Sep 15 06:16:10 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 14 Sep 2006 - 23:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.