google R style guide

June 19, 2012
By

(This article was first published on Tony's bubble universe » R, and kindly contributed to R-bloggers)

After writing several hundreds of lines of R codes, I start to pay some attention to my coding style. Fortunately, I find a document about R style guide in google code. Surprisingly, R is among the most popular programming languages, such as C++, objective-C, python, java and html. I didn’t realize R has become so popular; I thought it was just a statistical language used by a small group of geek researchers who wouldn’t even show up in public during the daytime. Now, I’m glad that R is accepted by more and more people. Even the Guardian datablog is using R to present their data. What a choice! 

In the google style guide, there are listed 14 R style rules and 3 more R language rules. I’ll introduce some rules in the following as these were actually my issues:

  • Rule 2: Identifiers written like variable.name and FunctionName. I was using function.name() because R uses functions like plot.table(), mean.data.frame(), etc. But in the most recent packages, this rule is more accepted.
  • Rule 3: Line length no more than 80 characters. I used to write long codes which I couldn’t see the end.
  • Rule 4: Indentate two spaces, no tabs. OK, I have changed my indentation from one tab to 4 spaces, which is recommended for python programing. Now I am changing to two spaces.
  • Rule 8: Don’t use semicolons. I could adapt to it but I just want to know why? Sometimes it’s convenient.
  • There are several others. Rules like spacing, using <- not =, { in right places, just have codes easy to read. Rules including commenting, writing definitions and examples make codes easy to understand. And those three R language rules would kept you from some serious troubles, I think. 

To leave a comment for the author, please follow the link and comment on his blog: Tony's bubble universe » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.