From murdoch at stats.uwo.ca  Wed Sep  9 15:55:22 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Wed, 09 Sep 2009 09:55:22 -0400
Subject: [Rd] Finding the environment of a promise
In-Reply-To: <f8e6ff050909090630t69a76ca7k2c4ea4cc35678d40@mail.gmail.com>
References: <f8e6ff050909090630t69a76ca7k2c4ea4cc35678d40@mail.gmail.com>
Message-ID: <4AA7B3CA.2080702@stats.uwo.ca>

On 9/9/2009 9:30 AM, Hadley Wickham wrote:
> Hi all,
> 
> Is it possible to determine the environment in which a promise will be
> evaluated?  e.g.
> 
> f <- function(code) { force(code) }
> f({
>   a <- 1
>   b <- 2
> })
> 
> Is there any way to tell from within f that a and b will be created in
> the global environment?

I don't think so in R code, but C code to do it would be possible.  It 
needs to be in C code to avoid forcing the promise.

I think we'd be reluctant to make an R function available to do this, 
because it requires non-standard evaluation, and it's not something a 
normal function should care about.  (The promise belongs to the caller, 
not to the function:  why would the function need to play with it?  It 
should be happy with the value, or maybe a text representation of the 
promise, for labelling purposes.)

Duncan Murdoch



[Rd] Finding the environment of a promise
Duncan Murdoch