- Reproducibility
- FAIR data principles: findable, accessible, interopable, reusable
- Make it usable for other scientists – including future you!
See papers listed at the Riffomonas Tutorial for further reading on reproducibility.
5/21/2019
See papers listed at the Riffomonas Tutorial for further reading on reproducibility.
“Document Design and Purpose, Not Mechanics” - Wilson et al. 2014
In other words, “Why, not how”.
Don’t do this:
i <- i + 1 # increment `i` by 1
Try to write code that is self-documenting.
counter instead of ipatient_metadata instead of dfdata_cleaned instead of df2Include a comment at the top of your R script to briefly describe what it does at a high level.
# Generate plots from mothur sensspec files for comparing clustering algorithms. library(ggplot2)
roxygen2 syntax for man/ files.usethis & devtools.R Markdown.pkgdown.roxygen2 syntaxDocument functions in R/*.R files
#' Add together two numbers.
#'
#' @param x A number.
#' @param y A number.
#' @return The sum of \code{x} and \code{y}.
#' @examples
#' add(1, 1)
#' add(10, 1)
add <- function(x, y) {
x + y
}
roxygen2 syntaxDocument datasets in R/data.R
#' Prices of 50,000 round cut diamonds.
#'
#' A dataset containing the prices and other attributes of almost 54,000
#' diamonds.
#'
#' @format A data frame with 53940 rows and 10 variables:
#' \describe{
#' \item{price}{price, in US dollars}
#' \item{carat}{weight of the diamond, in carats}
#' ...
#' }
#' @source \url{http://www.diamondse.info/}
"diamonds"
roxygen2 syntaxDocument the package in R/package_name.R
#' foo: A package for computating the notorious bar statistic. #' #' The foo package provides three categories of important functions: #' foo, bar and baz. #' #' @section Foo functions: #' The foo functions ... #' #' @docType package #' @name foo NULL
Let’s document code from the Riffomonas minimalR tutorial!
minimalR. Edit R/minimalR.R.baxter_metadata. Edit R/data.R (raw data in inst/extdata/, processed data in data/)get_metadataget_bmiget_bmi_categoryis_obeseClone this repo
git clone https://github.com/SchlossLab/documenting-R
or if you previously cloned it, pull new commits:
cd path/to/documenting-R/ ; git pull
Checkout a new branch
git checkout -b descriptive-branch-name
After modifying your part, commit your changes
git add . ; git commit -m "descriptive commit message"
Push your changes
git push -u origin descriptive-branch-name
Open a pull request on GitHub to merge your branch into master. Mention your issue number(s) & assign me to the PR.

Setup an R package
library(usethis) library(devtools) create_package(file.path(getwd()))
Specify dependencies
use_package("dplyr")
use_package("readxl")
Compile documentation
devtools::document()