Skip to content

Latest commit

 

History

History
75 lines (53 loc) · 2.75 KB

coding-standards.md

File metadata and controls

75 lines (53 loc) · 2.75 KB

Coding Standards

General Overview

  1. The 80 characters rule.
  2. When possible, structure your code as sections/files, with files holding similar functions and sections to give internal structure to your file.
  3. Use white space for indenting, 4 characters.
  4. Explain yourself: Add comments.

Control-flow statements

  1. Single line if

    # If it's only a single like
    if (...)
        ...then...
  2. Multiple lines ifelse

    # Several blocks
    if (...) {
        ...then...
    } else {
        ...
    }

Variable/Objects names

  1. 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 or myObject.
  2. Whenever possible, use informative names, e.g. loglike instead of var1

Software Thinking

Development Workflow

General Overview

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:

  1. Write down the function.
  2. Document the function: Input/output, examples, and references.
  3. Write down the tests.
  4. Build (compile) the package.
  5. Run the tests and make sure fun didn't break anything.
  6. Update the news.md and ChangeLog files (that sounds like a good idea).

Misc

R-packages

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

More references