From simon.urbanek at r-project.org  Wed Sep  9 17:09:17 2009
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Wed, 9 Sep 2009 11:09:17 -0400
Subject: [Rd] Finding the environment of a promise
In-Reply-To: <da79af330909090640x19840eefr21002757ca52c835@mail.gmail.com>
References: <f8e6ff050909090630t69a76ca7k2c4ea4cc35678d40@mail.gmail.com>
	<da79af330909090640x19840eefr21002757ca52c835@mail.gmail.com>
Message-ID: <FCD73B2E-BF59-45B9-9685-B1E0DF641B72@r-project.org>


On Sep 9, 2009, at 9:40 , Henrique Dallazuanna wrote:

> If I understand your question, you can get the environment with  
> sys.frame:
>
> f <- function(code){
>    print(sys.frame())

^-- this will always return R_GlobalEnv (see ?sys.frame - which = 0 by  
default) regardless of the function and promise.

Also the question was about the environment of the promise, not the  
function. Technically a promise can be evaluated anywhere since it  
ignores the evaluation environment and will use its creation  
environment which is what Hadley was trying to get at (and as Duncan  
was saying it's not something that is or should be available at R  
level as it's an internal implementation detail).

Cheers,
Simon


>    force(code)
> }
>
> f({
> a <- 1
> b <- 2
> })
>
> On Wed, Sep 9, 2009 at 10:30 AM, Hadley Wickham <hadley at rice.edu>  
> 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?
>>
>> Thanks,
>>
>> Hadley
>>
>> --
>> http://had.co.nz/
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>
>
> -- 
> Henrique Dallazuanna
> Curitiba-Paran?-Brasil
> 25? 25' 40" S 49? 16' 22" O
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Finding the environment of a promise
Simon Urbanek