Notes

The following is based on best practice documents mainly from Hadley Wickham but complemented with a few ideas. A particular point of confusion is naming in R which consists of mixture of camelcase or names with words separated by underscore. Since the latter is the standard in GNU and R is a GNU project we adhere in case of doubt to GNU best practices.

Principles

Code organization

  1. R code should be organized in packages
  2. Package structure follows R package guidelines
  3. One file per user visible function
  4. Aim at 25-30 lines per function
  5. The R directory for packages does not allow sub-directories; so, all code files need to go in this directory. Grouping files may be achieve through shared prefixes.

Coding environment

  1. The standard IDE for R at CIP is RStudio.
  2. Editor standard formatting options should be adhered to. Particularly, line length should be 80 characters and indentation be set to two space characters.
  3. The standard documentation is to be created in roxygen2 format.
  4. The standard source code management tool is git.
  5. Source code is hosted on github.
  6. For vignettes knitr is to be used.
  7. For formatting consistency source code should be formmatted by formatR.
  8. Issues are tracked on github.
  9. All packages must have tests (using testthat).
  10. Use the devtools package for facilitating the installation of additional coding support tools.
  11. Continuous integration online services are used (travis-ci and AppVeyor)

Package development workflow

  1. For a fresh package start with creating an empty package on github. Choose a unique name (check CRAN and bioconductor sites for name conflicts). The package name must be in English and all lowercase with only alphanumeric characters. Choose 'R' in gitignore, create a Readme.md file and add a MIT license.
  2. From RStudio create a package from github using the URL 2.1. Use devtools::use_travis() to prepare for continuous integration 2.2. Use devtools::use_testthat() to prepare testing infrastructure 2.3. Use devtolls::use_vignette("my_name") 2.4. Enable automated creation of man files via roxygen2 in RStudio options 2.5. Set Sweave to use knitr in RStudio options
  3. Edit the DESCRIPTION file according to R CRAN instructions
  4. Add tests using testthat. 4.1. Add features on github 4.2. Use auto_test feature by opening a separate R instance and point auto_test to the current package in progress.
  5. Add code. 5.1. Each function must have a corresponding working example of usage (best under a separate inst/examples directory). 5.2. Profile code.
  6. Use atomic git commits. Add meaningful comments to commit messages and add references to git issues using github key words like 'closes'.
  7. Add documentation to source code files in roxygen2 format while complying with R package development guidelines. 6.1 Use formatR package for correct formatting; paramters: indent=2 and arrow=TRUE; that is: formatR::tidy_dir("R", indent=2, arrow=TRUE)
  8. Push source code at least daily to github. When connected to travis-ci (2.1) this will also trigger the automated checking on that platform (Ubuntu)
  9. Use build and check locally - for a good package there must not be any warnings nor errors nor notes (except 1 note when an existing package is updated.)
  10. Use winbuild site for checking your package on current and next R versions.
  11. A new package should be published during the first phase only on github.
  12. A package should be only published on CRAN when considered a stable first version.
  13. Changes to user visible function names and parameters must be managed (see Hadley Wickham's best practices.)

Style guide

General

Package names

Package versioning

File names

Constant names

Variable and function names

S4 objects

Syntax

Spacing

Curly braces

Line length

Indentation

Assignment

Comments

S4 objects

Testing



c5sire/ciptools documentation built on May 13, 2019, 10:31 a.m.