-
Notifications
You must be signed in to change notification settings - Fork 21
Dev Docs Code Style Guide
We have tried to stick as much as possible to using consistent code styles when developing the SpaDES
package codebase. This style guide is largely adapted from Hadley Wickham's Advanced R Style Guide, but there are some differences. We encourage contributors to adhere to these coding conventions.
-
Use descriptive lowercase filenames.
-
Use dashes (instead of underscores or periods).
-
Use
.R
as the file extension. -
If files need to be run in a specific sequence, use a number prefix
# good plotting-functions.R 0-prepare-workspace.R 1-load-data.R 2-run-analysis.R # bad PLOT_functions.r a.r
-
Variable and object names should be concise and descriptive nouns.
-
Functions and methods should be named using concise and descriptive verbs.
-
Avoid using the names of existing variables and functions.
-
Use lowerCamelCase.
-
Do not use periods nor underscores.
-
Use
TRUE
andFALSE
instead ofT
andF
.# good beetleSurvival findArea() # bad mean.vals to_extract_mean_raster_value_and_prob_cross_pathway_roads()
- Use spaces around operators (e.g.,
+
,-
,=
,<-
). - Don't use spaces around
:
,::
, and:::
. (Should this also apply to:=
indata.table
?) - Spacing can be used to improve alignment/readability.
-
{
should never be on its own line (it should end the line; never begin it). -
}
should always be on its own line unless followed byelse
. - Use curly braces for
if else
statements. - Code inside curly braces should be indented.
- Try to limit lines to 80 characters.
- Indent using 2 spaces. Only use spaces (no tabs).
- Spacing can be used to improve alignment/readability.
- Use
<-
instead of=
.
- Use comments to explain why (and if the code is complicated or uses shorthand, what) the code is doing.
- Use a single
#
(with trailing space) to denote commented lines. - Document every class, function, etc. you write.
- Use
#'
to denote documentation blocks (seeroxygen2
documentation:vignette("rd", package = "roxygen2")
).
- Installation
- Getting started
- Help and package vignettes
- SpaDES 4 dummies
- Try me!
- Debugging
- Caching
- Alternate cache backends
- Frequently asked questions
- SpaDES Users Group
-
Wolves recolonizing the Italian Alps - This is a rewrite in
SpaDES
of Marucco & McIntire 2010.