Generally, we follow Hadley Wickham's R style guide.
Most importantly:
Use <-
for assignment, not =
.
Operators do get spacing, parentheses do not: if (x + 1) print("yes")
Use short, clear, and consistent variable names.
[[Clearly comment your code and data|Documentation]].
We're using a standard set of R packages to handle many tasks–mostly from what is known as the tidyverse. These include: dplyr for data manipulation and processing; tidyr for data reshaping; assertthat for assertions; tibble for better data frames; * magrittr for building pipelines.
A word about pipelines: we aim to use these consistently and when it makes sense...but don't take things to extremes. Sometimes y <- f(g(x))
really is the clearest notation.
The package tests will raise an error for all of these:
R's match()
function
The reshape
or reshape2
packages (i.e. melt
or cast
)
Loops (this is not an ironclad prohibition, but should be very rare)
R's ifelse
function - if necessary use dplyr::if_else
instead
Any of R's apply
family of functions, rowMeans
, etc. (again, with rare exceptions)
Successive mutate()
calls. See Hints for speed
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.