In my function I am trying to return multiple computed items (separated by commas). The function does what I need, but I get a warning message that multi-argument returns are deprecated. Is this a warning I should heed, or is there a more elegant and warning free way of achieving the same end? Thanks --------------------------------- [[alternative HTML version deleted]]
Gabor Grothendieck
2006-Jan-30 18:45 UTC
[R] Warning message when returning multiple items
Return a list: f <- function(x) list(x = x, x.squared = x*x) On 1/30/06, Krish Krishnan <rkrishnan8216 at yahoo.com> wrote:> In my function I am trying to return multiple computed items (separated by commas). The function does what I need, but I get a warning message that multi-argument returns are deprecated. Is this a warning I should heed, or is there a more elegant and warning free way of achieving the same end? Thanks > > > > --------------------------------- > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
On Mon, 2006-01-30 at 10:35 -0800, Krish Krishnan wrote:> In my function I am trying to return multiple computed items > (separated by commas). The function does what I need, but I get a > warning message that multi-argument returns are deprecated. Is this a > warning I should heed, or is there a more elegant and warning free way > of achieving the same end? Thanksfoo <- function(x) { x5 <- x * 5 rootx <- sqrt(x) squaredx <- x^2 return(list(x5 = x5, rootx = rootx, squaredx = squaredx)) }> foo(9)$x5 [1] 45 $rootx [1] 3 $squaredx [1] 81 HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
For the last few versions of R (don't remember when the change happened now), you need to explicitly wrap the objects in a list, instead of simply having them in return(). I.e., instead of return(a=thing1, b=thing2), you simply use list(a=thing1, b=thing2) as the last line of the function. Andy From: Krish Krishnan> > In my function I am trying to return multiple computed items > (separated by commas). The function does what I need, but I > get a warning message that multi-argument returns are > deprecated. Is this a warning I should heed, or is there a > more elegant and warning free way of achieving the same end? Thanks > > > > --------------------------------- > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Apparently Analagous Threads
- Strange axis labels?
- HABTM -VS- belongs_to/has_many, for self-referential joins
- Is there a way to abstract the updating of other parts of the page after an Ajax request without putting using the standard view file?
- Re: Some advice on DB modeling
- If form changed ask if you really want to exit page...