Hi, On Wed, Feb 17, 2010 at 4:09 PM, Randall Wrong <randall.wr...@gmail.com> wrote: > Dear R users, > > I have multi-argument returns in a function and I am warned by the program > they are deprecated. > > I have found this in the R-help archives : > > http://tolstoy.newcastle.edu.au/R/help/01c/0319.html > http://tolstoy.newcastle.edu.au/R/help/01c/0356.html > > Since I am not too good at programming, the list solution seems the better > one for me. It is also the one advocated by Kevin Murphy. > > So rather than writing return(x,y,z), I should write at the end of my > function : > > g=function() { > > #... > > result=list(x,y,z) > return(result) > } > > Is that correct ?
FYI, in R the last line of a function is its return value, so you could simply do: g <- function() { list(x=x, y=y, z=z) } > Then shoud l use g[1] or g[[1]] ? Just to avoid a mistake or ambiguity here, I wouldn't use "g" as a variable because you are using that as your function name. So after defining the function `g`, you could do: myvalue <- g() Then you would use: myvalue[[1]] myvalue[1] would return you a list that has one element in it (the first one), where as using myvalue[[1]] just gives you the first element of the list. Using "named" arguments when constructing your list as I did (eg. list(x=x, ...)), you can then also do: myvalue$x Hope that helps, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.