├── LICENSE.md
├── README.md
├── _config.yml
├── _includes
├── footer.html
├── header.html
├── js.html
└── syntax.css
├── _layouts
└── default.html
├── font
├── fontello.eot
├── fontello.svg
├── fontello.ttf
└── fontello.woff
├── index.html
└── stylesheet.css
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Jean Fan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # R Style Guide
2 | ### Best practices for readable, sharable, and verifiable R code
3 |
4 | R is a high-level programming language used primarily for statistical computing and graphics. R does not have any well defined coding recommendations or de facto standards. This style guide provides some recommendations based on personal experience and expert opinions (see Additional Guides). Use your best judgement and common sense when deciding whether to adhere to these recommendations. Be consistent. Use style to enhance legibility. Ultimately, a unified style will help make collaboration and sharing code easier.
5 |
6 | **[Start reading ☞](http://jefworks.github.io/R-style-guide/)**
7 |
8 | Feel free to fork or clone and make your own R style guide for your lab, team, or collaborative R project.
9 |
10 | ## Additional Guides
11 | - https://style.tidyverse.org/
12 | - http://r-pkgs.had.co.nz/style.html
13 | - https://google.github.io/styleguide/Rguide.xml
14 | - https://docs.google.com/document/d/1esDVxyWvH8AsX-VJa-8oqWaHLs4stGlIbk8kLc5VlII/edit
15 | - http://master.bioconductor.org/developers/how-to/coding-style/
16 |
17 | ## Inspiration
18 | - http://mdo.github.io/code-guide/
19 |
20 | ## Other Info
21 | - made with [Jekyll](https://help.github.com/articles/using-jekyll-with-pages/)
22 | - color scheme from [Shiny](http://shiny.rstudio.com/)
23 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | name: R Style Guide
2 | description: Best practices for readable, sharable, and verifiable R code
3 | url: http://jefworks.github.io/R-style-guide/
4 | markdown: rdiscount
5 | permalink: pretty
--------------------------------------------------------------------------------
/_includes/footer.html:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/_includes/header.html:
--------------------------------------------------------------------------------
1 |
2 |
7 | R is a high-level programming language used primarily for statistical computing and graphics. R does not have any well defined coding recommendations or de facto standards. This style guide provides some recommendations based on personal experience and expert opinions (see Additional Guides). Use your best judgement and common sense when deciding whether to adhere to these recommendations. Be consistent. Use style to enhance legibility. Ultimately, a unified style will help make collaboration and sharing code easier.
8 |
Variables should preferably adhere to camelCase. But for backward compatibility with historical functions, all lower case letters and words separated with . is also accepted
76 |
Function and class names should adhere to camelCase
77 |
Do not use . with class names due to potential confusion with S3 method declarations
78 |
119 | {% highlight R %}
120 | # Good
121 | x <- 23
122 | y <- 12
123 |
124 | # Bad
125 | x = 23; y = 12
126 | 23 -> x
127 | {% endhighlight %}
128 |
129 |
130 |
131 |
132 |
133 |
Spacing
134 |
135 |
Place spaces around all binary operators such as =, +, -, <-, etc.
136 |
Place a space before the (, except in a function call
137 |
Use space after a comma
138 |
139 |
140 |
141 | {% highlight R %}
142 | # Good
143 | someFunction <- function(a, b, c, d = 100) {
144 | if (a < d) {
145 | a <- (b + c) * d
146 | }
147 | }
148 |
149 | # Bad
150 | someFunction <- function(a,b,c,d= 100) {
151 | if(a
155 |
156 |
157 |
158 |
159 |
Curly Braces
160 |
161 |
Do not place { on its own line
162 |
Place } on its own line unless followed by else
163 |
Surround else statements with curly braces
164 |
165 |
166 |
167 | {% highlight R %}
168 | # Good
169 | if (a < d) {
170 | a <- (b + c) * d
171 | } else {
172 | a <- d
173 | }
174 |
175 | # Bad
176 | if (a < d)
177 | {
178 | a <- (b + c) * d
179 | } else a <- d
180 | {% endhighlight %}
181 |
182 |
183 |
184 |
185 |
186 |
Line Length
187 |
188 |
Keep each line less than 80 characters
189 |
Align lines by shared features like parameters if possible