Re: [R] Warning message when returning multiple items

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Tue 31 Jan 2006 - 05:54:17 EST

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? Thanks

foo <- 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.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help@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
Received on Tue Jan 31 06:23:29 2006

This archive was generated by hypermail 2.1.8 : Tue 31 Jan 2006 - 08:25:20 EST