Finding the environment of a promise
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