Skip to content

R Package Guidelines

Jeff Walker edited this page Feb 9, 2015 · 1 revision

This page will contain instructions on setting up and organizing R packages.

Guidelines

Each package will:

  • have a short and descriptive name in camel case, with the prefix conte (e.g. conteFlow).
  • be stored in its own git repository so that the devtools::install_github() function can be used for local installation. The name of the repo should be the same as the name of the package (e.g. conteFlow).
  • will contain an example dataset in *.Rdata/*.rda format, which is stored in the /data directory. If other datasets need to be included but are not in binary Rdata format (e.g. geospatial data, or raw csv) then these should be stored in the directory inst/extdata. See this StackOverflow discussion.
  • contain at least one vignette as an R markdown document that provides an example of how to use the package for performing an analysis or model run. See the R Package Vignettes page for more details on how to set up and configure the package vignettes.

Tips & Tricks

A good description of creating documentation for functions with the roxygen2 package (same as oxygenize option in RStudio) can be found on the CRAN site. A template for a function is located in this repository.

Function Documentation Template for oxygenize

Use @export if you want the user to access the function and leave it out if the function will ONLY ever be used by other functions within the package.

#' @title Name of the function
#'
#' @description
#' \code{functionName} One sentence description of the package
#'
#' @param x Numeric vector of awesome stuff
#' @param y Dataframe of observed stuff
#' @return Returns a dataframe of the best stuff
#' @details
#' blah, blah, something, something
#' @references
#' Hadley Wickham, Peter Danenberg and Manuel Eugster (2014). roxygen2: In-source documentation for R. R package version 4.0.1. http://CRAN.R-project.org/package=roxygen2
#' @examples
#'
#' \dontrun{
#' foo <- functionName(x, y)
#' }
#' @export
functionName <- function(x, y) {
bar <- x + y$count
return(as.data.frame(bar))
}

References