Warning message when returning multiple items

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Warning message when returning multiple items

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]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Warning message when returning multiple items

Gabor Grothendieck
Return a list:

   f <- function(x) list(x = x, x.squared = x*x)


On 1/30/06, Krish Krishnan <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Warning message when returning multiple items

Gavin Simpson
In reply to this post by Krish Krishnan
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.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Warning message when returning multiple items

Liaw, Andy
In reply to this post by Krish Krishnan
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]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Warning message when returning multiple items

Krish Krishnan
In reply to this post by Krish Krishnan
 Thanks everyone.  Returning the items in a list worked like a charm.


                       
---------------------------------

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html