knitr::opts_chunk$set(eval = FALSE)
See papers listed at the Riffomonas Tutorial for further reading on reproducibility.
r
i <- i + 1 # increment `i` by 1counter 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_obese{bash}
git clone https://github.com/SchlossLab/documenting-R
or if you previously cloned it, pull new commits:
{bash}
cd path/to/documenting-R/ ; git pull{bash}
git checkout -b descriptive-branch-name{bash}
git add . ; git commit -m "descriptive commit message"{bash}
git push -u origin descriptive-branch-nameOpen a pull request on GitHub to merge your branch into master. Mention your issue number(s) & assign me to the PR.
{height=275px}
{height=275px}
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()
library(rmarkdown) rmarkdown::render('documentingR.Rmd', output_file = 'docs/documentingR.html')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.