- The 80 characters rule.
- When possible, structure your code as sections/files, with files holding similar functions and sections to give internal structure to your file.
- Use white space for indenting, 4 characters.
- Explain yourself: Add comments.
-
Single line
if
# If it's only a single like if (...) ...then...
-
Multiple lines
ifelse
# Several blocks if (...) { ...then... } else { ... }
- Never use dots to name objects, e.g.
my.object
. Both R and C++ use the dot symbol to access (or call) methods. Instead use either underscore or capital letters, e.g.my_object
ormyObject
. - Whenever possible, use informative names, e.g.
loglike
instead ofvar1
Unfolding the "Software Thinking", once you have set up the project (whereas an R package, C/C++ library, etc.), the development workflow is an iterative process. For each fun
in functions
do the following:
- Write down the function.
- Document the function: Input/output, examples, and references.
- Write down the tests.
- Build (compile) the package.
- Run the tests and make sure
fun
didn't break anything. - Update the
news.md
andChangeLog
files (that sounds like a good idea).
For R package development
devtools
: An R package for package developers.roxygen
: For documenting functions.testthat
: For making testing fun.codecov
: To track the code coverage.
For reproducible research
ProjectTemplate
A complete workflow for reproducible research.represtools
An alternative to ProjectTemplate.CodeDepends
Analyzes your code to see dependencies.reproducible
An alternative to ProjectTemplate.