[Rd] Finding the environment of a promise
Duncan Murdoch
murdoch at stats.uwo.ca
Wed Sep 9 15:55:22 CEST 2009
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
More information about the R-devel
mailing list