[R] Problems accessing environment() in function
Heiko Neuhaus
webmaster at euros4click.de
Tue May 1 19:57:43 CEST 2012
Hi all,
I am trying to create a list of all variable/value combinations in
environment().
When a function with unset arguments is called, the method I have been
using fails with a "missing argument" error. However it should be
possible to simply skip these missing objects in the generation of the list?
Could anyone recommend me a better way (that does not use a slow
for/eval-combination) to achieve the desired effect?
You can easily reproduce my problem using this code:
------------------------------
test1 <- function(a, b, c)
{
x <- as.list(environment())
print ("hi from test1!")
test2(a = a, b = b, c = c)
}
test2 <- function(a, b, c)
{
# PROBLEM: Why can't I get a list as in test1() here?
x <- as.list(environment())
print ("hi from test2!")
}
test1()
------------------------------
I want my list "x" in test2() to work behave just like "x" in test1().
(In this example the correct list in test2() would be empty).
Thanks a lot for your time.
Best wishes,
Heiko Neuhaus
More information about the R-help
mailing list