Skip to content
Back to formatted view

Raw Message

Message-ID: <4FA02417.9070805@euros4click.de>
Date: 2012-05-01T17:57:43Z
From: Heiko Neuhaus
Subject: Problems accessing environment() in function

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