Skip to content

R Code Style Guides

christophergandrud edited this page Jun 6, 2012 · 1 revision

In natural language writing you don't necessarily need to follow a style guide for things such as punctuation. People could probably figure out what you are saying. But it would be a lot easier for your readers if you use consistent rules. The same is true when writing R code. It's good to follow consistent rules for formatting your code so that:

  • it's easier for others to understand,

  • it's easier for you to understand.

Just like in natural language, there are a number of R style guides. Most of them are similar to the Google R Style Guide. Hadley Wickham has a nicely presented style guide. See also this blog post by Pairach Piboonrungroj for a list of R style guides.

You can use the package formatR to automatically reformat your code so that it is easier to read.