[R] Writing a workable function
Yves Gauvreau
cyg at sympatico.ca
Mon Aug 14 16:19:37 CEST 2000
Hi,
If I understand you correctly you would like to print the start time, read
your data and print then end time. So, as one suggested, use cat to output
any values you want to see that are local to your function and either return
the result using "return( ... )" or place the variable or object you want as
the last statement of your function. You may want to know the elapse time
instead of figuring it out manually. I think this can be done using the
chron library, have a look and have fun.
Regards.
Yves
----- Original Message -----
From: "Charles RAUX" <Charles.Raux at let.ish-lyon.cnrs.fr>
To: "Robert Gentleman" <rgentlem at stat.auckland.ac.nz>
Cc: "r-help" <r-help at stat.math.ethz.ch>
Sent: Monday, August 14, 2000 7:09 AM
Subject: Re: [R] Writing a workable function
> 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
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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