Re: [R] Return a list

2008-09-26 Thread hadley wickham
> it depends on what the original author wanted. > > with constructs a new environment, and all assignments, if any, made in > the expression evaluated within with are invisible to the outside > (unless one plays with environments, again): > > x = 1:10 > a = 3 > with(test(), { x[1:3] = c(a,b,c); x

Re: [R] Return a list

2008-09-26 Thread Wacek Kusnierczyk
that's likely to work, but it's even worse than my non-functional version: the destructive operation on the test's caller's environment is performed here by the callee (test), and you can get ugly surprises if you forget that test does that. i'd consider this (and the 'for (name in names(result))

Re: [R] Return a list

2008-09-26 Thread Wacek Kusnierczyk
Bert Gunter wrote: > But why do this? Just leave the (preferably named) variables as list > components and work with them there. > > 1. ?comment tells you how to add a comment attribute to the list for self > documentation (what were the components? how are they related? etc.) > > 2. ?with shows y

Re: [R] Return a list

2008-09-26 Thread N. Lapidus
The answers that were previously given allow you to easily extract results from your returned list, but if I understand well, this list is created only because you cannot return several arguments whereas you need to keep the values of a, b, c, etc. Am I right? Another solution would be to directly

Re: [R] Return a list

2008-09-26 Thread Bert Gunter
Friday, September 26, 2008 12:40 PM To: Mike Prager Cc: R help Subject: Re: [R] Return a list Mike Prager wrote: > "Stefan Fritsch" <[EMAIL PROTECTED]> wrote: > > >> I have several output variables which I give back with the list command. >> >> test &l

Re: [R] Return a list

2008-09-26 Thread Wacek Kusnierczyk
Mike Prager wrote: > "Stefan Fritsch" <[EMAIL PROTECTED]> 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 >> var

Re: [R] Return a list

2008-09-26 Thread Mike Prager
"Stefan Fritsch" <[EMAIL PROTECTED]> 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()

Re: [R] Return a list

2008-09-26 Thread Henrique Dallazuanna
Try this: sapply(names(result), function(nm)assign(nm, result[[nm]], envir = globalenv())) On Fri, Sep 26, 2008 at 10:57 AM, Stefan Fritsch <[EMAIL PROTECTED]> wrote: > Dear R Users, > > another problem for me is the output of a function. > > I have several output variables which I give back wit

Re: [R] Return a list

2008-09-26 Thread baptiste auguie
?attach or ?with Hope this helps, baptiste On 26 Sep 2008, at 14:57, Stefan Fritsch wrote: Dear R Users, another problem for me is the output of a function. I have several output variables which I give back with the list command. test <- function {return(list(a,b,c,d,e,f,g,...))}

[R] Return a list

2008-09-26 Thread Stefan Fritsch
Dear R Users, another problem for me is the output of a function. 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 <