[R] Decent R code does NOT end lines in ';' !

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue, 11 Dec 2007 09:15:17 +0100

>>>>> "TK" == Talbot Katz <topkatz_at_msn.com> >>>>> on Mon, 10 Dec 2007 14:16:52 -0500 writes:

    TK> Hi.  

    TK> I have a procedure that reads a directory, loops through
    TK> a set of particular .RData files, loading each one, and
    TK> feeding its object(s) into a function, as follows:

    TK> cvListFiles<-list.files(fnDir);
    TK> for(i in grep(paste("^",pfnStub,".*\\.RData$",sep=""),cvListFiles)){
    TK> load(paste(fnDir,cvListFiles[i],sep="/"));
    TK> myFunction(rliObject);

    TK> rm(rliObject);
    TK> };  

        [.............]

I don't know where you got the idea to end R statements with ";". I find it atrocious. It just does not belong to the S language and its R implementation.

Please don't do it

OTOH, *please* do

This would make your above code into something like

 cvListFiles <- list.files(fnDir)
 for(i in grep(paste("^", pfnStub,".*\\.RData$", sep = ""), cvListFiles)) {

     load(paste(fnDir, cvListFiles[i], sep = "/"))
     myFunction(rliObject)
     rm(rliObject)

 }

Something many readers on this list will much prefer to your original, and hence start considering to look at ..

Martin Maechler,
(S user since ca. 1987; member of R-core)



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 11 Dec 2007 - 08:27:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 11 Dec 2007 - 08:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.