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/
If I understand your question, you can get the environment with sys.frame:
f <- function(code){
print(sys.frame())
force(code)
}
f({
a <- 1
b <- 2
})
On Wed, Sep 9, 2009 at 10:30 AM, Hadley Wickham <hadley@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@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]]
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
Possibly Parallel Threads
- Capturing environment associated with a promise
- Using substitute to access the expression related to a promise
- Data frame printing buglet when multiple empty column names
- RFC: (in-principle) native unquoting for standard evaluation
- Detecting development environment