Writing Effective R Package Documentation

Learn best practices for documenting R packages using roxygen2 and creating comprehensive vignettes.

RDocumentationPackage Development

Introduction

Good documentation is crucial for package adoption and usability. This guide covers best practices for documenting R packages using roxygen2 and vignettes.

Function Documentation

R
#' Calculate weighted mean with handling for missing values
#' 
#' @param x Numeric vector
#' @param weights Numeric vector of weights
#' @param na.rm Logical, should missing values be removed?
#' 
#' @return Weighted mean of x
#' @export
#' 
#' @examples
#' x <- c(1, 2, NA, 4)
#' weights <- c(0.2, 0.3, 0.1, 0.4)
#' weighted_mean(x, weights, na.rm = TRUE)
weighted_mean <- function(x, weights, na.rm = FALSE) {
  # Function implementation
}

Writing Vignettes

Vignettes provide detailed examples and use cases for your package functionality.

Resources