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

Martin Maechler maechler at stat.math.ethz.ch
Tue Dec 11 09:15:17 CET 2007


>>>>> "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
 -- it hurts the eyes of most experienced R users
 -- it's extra clutter
 -- internally each extra ";" is an extra empty statement

OTOH, *please* do
 -- indent R code and 
 -- use spaces to increase readability 

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)



More information about the R-help mailing list