[R] Writing a workable function

Winfried Theis theis at statistik.uni-dortmund.de
Mon Aug 14 13:13:15 CEST 2000


Hello!
On 14-Aug-00 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?
I don't think they are ignored, but you don't print out, give back, resp., any
value. So if you want as output a list of date and the data.frame do:

tt <- function{
        mc <- read.csv2("machines.txt",na.strings="")
        mc <- list(date(),mc)
        mc #This prints out or gives back the value of mc in this case the date
           #and the data.frame!
        }
In my (old!) version of R-Notes there is an example of a function on page 30,
but it lacks the explanation for the last line... I don't have the time to
check the FAQ right now, but I'm sure it's in there somewhere!
Cheers, Winfried
----------------------------------
E-Mail: Winfried Theis <theis at statistik.uni-dortmund.de>
Date: 14-Aug-00
Tel.: +49-231-755-5903                  Room: Mathematikgebäude, M832
Dipl.-Math. Winfried Theis, Graduiertenkolleg "Angewandte Statistik",
Universität Dortmund, 44221 Dortmund
----------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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