[R] Writing a workable function

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Aug 14 12:05:44 CEST 2000


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?

They are NOT ignored. Please read the FAQs (and the help pages).

If you want to return mc, you should specify it. In your case the last
expression (date()) will be returned.
Why do you use the argument "mc" in your function, if you don't use it?

The function 

tt <- function(filename) { 
    cat(date(), "\n")
    mc <- read.csv2(filename, na.strings="")
    return(mc)
}

might do what you want.

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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