Skip to content
Back to formatted view

Raw Message

Message-ID: <4FA1A53B.4010004@euros4click.de>
Date: 2012-05-02T21:20:59Z
From: Heiko Neuhaus
Subject: Problems accessing environment() in function
In-Reply-To: <4FA177C4.1090307@gmail.com>

Thank you very much for your suggestion.

> f <- function(a,b,c) {
> names <- ls(environment()) # get all the names
> result <- list()
> for (n in names) {
> if (!do.call(missing, list(as.name(n))))
> result[n] <- get(n)
> }
> result
> }

I have already figured out a very similar solution using for/eval that 
basically does the same. I was hoping that I would somehow could get 
around the ugly loop using a more elegant approach. The loop should have 
a negative impact on performance since my function is using a lot of 
parameters. I was hoping, that there was some flag to tell the as.list 
function to ignore non existing objects. If that is not possible I will 
have to accept this.

> If you put the ls() call later, you'll pick up other local variables
> (names, result, n) as well.

Of course. That is why I call it at the very first line of my function.

Thanks again!

Heiko Neuhaus