[R] Writing a workable function
Charles RAUX
Charles.Raux at let.ish-lyon.cnrs.fr
Mon Aug 14 13:09:20 CEST 2000
Since I have large data bases I only try to write a little function
that gives the current time, reads a data frame (and assigns it) and
at end gives the time. I have tried many forms but no one works.
Le 14 Aug 00 à 21:53, Robert Gentleman écrivait:
> Date: Mon, 14 Aug 2000 21:53:37 +1200
> From: Robert Gentleman <rgentlem at stat.auckland.ac.nz>
> To: Charles RAUX <Charles.Raux at let.ish-lyon.cnrs.fr>
> Subject: Re: [R] Writing a workable function
> On Mon, Aug 14, 2000 at 11:25:35AM +0100, Charles RAUX wrote:
> > After searching in R- Introduction, FAQ, help... I don't understand
> > this:
> > I write a function in a file (.R):
> > tt <- function(mc) { date()
> > mc<-read.csv2("machines.txt",na.strings="")
> > date()
> > }
> >
> > I source it in R and I type tt(). The answer is
> > > tt()
> > [1] "Mon Aug 14 11:18:25 2000"
> > >
> > The instructions following the first "date()" are ignored. Why?
>
> Actually they aren't. But perhaps your problem is that you don't
> realize that in R (as in many other languages, but certainly not all)
> parameters are passed by value. Thus, this is no way to assign a value
> to mc.
>
> tt<-function() read.csv2("machines.txt",na.strings="")
> mc<-tt()
>
> does what you seem to want.
>
> Notice that the value printed out,
> [1] "Mon Aug 14 11:18:25 2000"
> is, in some sense, not the result of a call to date, both of those
> are invisible at top level. Rather, the last call to date returns
> that string as its value and it is that value that is returned by
> the function and subsequently printed.
> > ---------------
> > Charles RAUX,
> > Laboratoire d'Economie des Transports
> > CNRS-Université Lumière Lyon 2-ENTPE
> > email : charles.raux at let.ish-lyon.cnrs.fr
> > http://www.ish-lyon.cnrs.fr/let
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > 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
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
> --
> +-------------------------------------------------------------------------+
> | Robert Gentleman phone : (64-9) 3737-599 ext 3946 |
> | Senior Lecturer fax : (64-9) 3737-018 |
> | Department of Statistics office : Room 206 Maths/Physics |
> | University of Auckland email : rgentlem at stat.auckland.ac.nz |
> +-------------------------------------------------------------------------+
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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