From hadley at rice.edu  Wed May  4 15:30:08 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Wed, 4 May 2011 08:30:08 -0500
Subject: [Rd] Capturing the complete unevaluated expression
 corresponding to function (body + formals)
In-Reply-To: <4DC14F98.7090303@gmail.com>
References: <BANLkTikYQ-E44a1bD3zVi75Y0cAfRooSsQ@mail.gmail.com>
	<4DC14F98.7090303@gmail.com>
Message-ID: <BANLkTi=-ZMKHG1TrpDQBh=ZNozFZuLGvbA@mail.gmail.com>

On Wed, May 4, 2011 at 8:07 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> On 04/05/2011 8:38 AM, Hadley Wickham wrote:
>>
>> Hi all,
>>
>> Is there any way to capture the complete unevaluated expression
>> corresponding to a function? ?I want the equivalent of
>>
>> x<- quote(function(x) x = 3)
>>
>> But captured after the function is created. ?Body and formals each
>> captures a part, but is there a built in way to get the whole thing?
>
> Internally, "function" is a function that produces a closure object. ?After
> you call it and the function is created, the inputs are gone, all you have
> is the result. ?But you can reconstruct it as you did below, because
> "function" basically just glues the parts together (and adds an environment
> as well).

Ok, I was getting confused because it looks like deparse and print(f,
useSource = F) can print the whole thing. But looking at the source, I
see that they reconstruct the function from the formals and the body
too.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



[Rd] Capturing the complete unevaluated expression corresponding to function (body + formals)
Hadley Wickham