R Style. An Rchaeological Commentary.
Paul Edward Johnson · 2013
After students have finished a semester of statistics with R, they may be ready to start preparing functions or packages. Those R users are the ones I’m trying to address with this note. It is important to realize that the readability of code makes a difference. It sometimes difficult to know that there is a “right way” and a “wrong way” because there are so many examples to study on CRAN. This note describes R style from an Rchaeological1 perspective. By examining the work of the R Core Development Team (R Core Team, 2012) and other notable package writers, we are able to discern an implicit style guide. However, this note is not “official” or endorsed from R Core.2 With one exception at the end of this note, none of the advice here is “my” advice. Instead, it is my best description of the standards followed by the leading R programmers. At one point, the only guide was the Google R style guide,3 which was used as a policy for R-related “Google Summer of Code” projects. There are many excellent suggestions in Hadley Wickham’s Style Guide.4 In what follows, I’ll try to explain why there are some variations among these projects and offer some advice about how we (the users) should sort through their advice.