Google's R Style Guide

R is a high-level programming language used primarily for statistical computing and graphics. The goal of the R Programming Style Guide is to make our R code easier to read, share, and verify. The rules below were designed in collaboration with the entire R user community at Google.
Important Ideas:
1. File names should end in .R and, of course, be meaningful.
2. Don't use underscores ( _ ) or hyphens ( - ) in identifiers. Identifiers should be named according to the following conventions. Variable names should have all lower case letters and words separated with dots (.); function names have initial capital letters and no dots (CapWords); constants are named like functions but with an initial k.
3. The maximum line length is 80 characters.
4. When indenting your code, use two spaces. Never use tabs or mix tabs and spaces.
5. Place spaces around all binary operators (=, +, -, <-, etc.).
6. An opening curly brace should never go on its own line; a closing curly brace should always go on its own line. 
7. Use <-, not =, for assignment.
8. Do not terminate your lines with semicolons or use semicolons to put more than one command on the same line.
9. Comment your code. Entire commented lines should begin with # and one space. Short comments can be placed after code preceded by two spaces, #, and then one space.
10. Function definitions should first list arguments without default values, followed by those with default values.
11. Functions should contain a comments section immediately below the function definition line.
12. Use a consistent style for TODOs throughout your code.

For more discussion of R coding style, convnetions and recomondations please check out R Coding Convention by Henrik Bengtsson and Style guide for R code by Andrew Gelman. 

Posted

0 comments

Leave a comment...