google R style guide
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.