Skip to content
Back to formatted view

Raw Message

Message-ID: <48DD3A8D.2030901@idi.ntnu.no>
Date: 2008-09-26T19:39:57Z
From: Wacek Kusnierczyk
Subject: Return a list
In-Reply-To: <rqbqd4d7gu28han6oh81of3m1f9s4iqffr@4ax.com>

Mike Prager wrote:
> "Stefan Fritsch" <fritsch at bips.uni-bremen.de> wrote:
>
>   
>> I have several output variables which I give back with the list command.
>>
>> test <- function	{return(list(a,b,c,d,e,f,g,...))}
>>
>> After the usage of the function I want to assign the variables to the output variables.
>>
>> result <- test()
>>
>> a <- result$a
>> b <- result$b
>> c <- result$c
>> d <- result$d
>> ...
>>
>> is there a more elegant way to assign these variables, without writing them all down?
>>
>>     

arguably ugly and risky, but simple:

for (name in names(result)) assign(name, result[[name]])

(note, for this to work you actually need to name the components of the
returned list: return(list(a=a,b=b,...)))

vQ