[R] Best way to export values from a function?

Daniel Nordlund djnordlund at verizon.net
Thu Jul 9 02:49:26 CEST 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Jason Rupert
> Sent: Wednesday, July 08, 2009 5:35 PM
> To: R-help at r-project.org
> Subject: [R] Best way to export values from a function?
> 
> 
> Maybe there is a great website out there or white paper that 
> discusses this but again my Google skills (or lack there of) 
> let me down.
> 
> I would like to know the best way to export several doubles 
> from a function, where the doubles are not an array.  
> 
> Here is a contrived function similar to my needs:
> 
> multipleoutput<-function(x)
> {
> 	squared<-x^2
> 	cubed<-x^3
> 	exponentioal<-exp(x)
> 	factorialVal<-factorial(x)
> 	
> }
> 
I can't vouch for the best way, but here is one way, return a list of the
values

multipleoutput<-function(x)
{
	squared<-x^2
	cubed<-x^3
	exponential<-exp(x)
	factorialVal<-factorial(x)
	return(list(squared=squared, cubed=cubed, exponential=exponential,
factorialVal=factorialVal))
}

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA




More information about the R-help mailing list