[R] Output args?

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jun 9 13:21:13 CEST 2000


> From: "Yves Gauvreau" <cyg at sympatico.ca>
> Date: Fri, 9 Jun 2000 07:05:42 -0400
> 
> Thanks for the prompt response.
> 
> I know nothing about S and about the fact that it is a functional language.
> I don't know much about English, functional languages, stats and maths
> either I'm just a retired high school teacher fiddling around to pass the
> time. But I know that when someone doesn't know something it only means that
> this someone doesn't know this subject and it certainly doesn't mean that
> this someone is necessarily stupid.

I do wonder if you might want to consider reading some of the documentation
about S to help you learn.  I would not expect to understand C programming
by trial-and-error.

> I find out by trial and error later that you can do the following.
> 
> foo<-function(x,y,z){
>   ...
>   abc<-list(a=x,b=y,c=z)
> }
> 
> and call
> 
> foo(1,2,3)
> 
> there is nothing outputted to the console which is close to what I ask in
> the first part of my query. I'll continue investigating to learn if it's
> possible to export or whatever is the right term, the variables I want so
> that there available for future use at the top level.

If you want to return an object, make it the last statement of your function,
that is use

foo<-function(x,y,z){
  list(a=x,b=y,c=z)
}
foo(1,2,3)

Your example *did* return something, invisibly:

> foo<-function(x,y,z){
+   abc<-list(a=x,b=y,c=z)
+ }
> foo(1,2,3)
> .Last.value
$a
[1] 1

$b
[1] 2

$c
[1] 3


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list