Learn R Programming

⚠️There's a newer version (7.3.2) of this package.Take me there.

roxygen2

The premise of roxygen2 is simple: describe your functions in comments next to their definitions and roxygen2 will process your source code and comments to automatically generate .Rd files in man/, NAMESPACE, and, if needed, the Collate field in DESCRIPTION.

Installation

# Install roxygen2 from CRAN
install.packages("roxygen2")

# Or the development version from GitHub:
# install.packages("pak")
pak::pak("r-lib/roxygen2")

Usage

The premise of roxygen2 is simple: describe your functions in comments next to their definitions and roxygen2 will process your source code and comments to produce Rd files in the man/ directory. Here's a simple example from the stringr package:

#' The length of a string
#'
#' Technically this returns the number of "code points", in a string. One
#' code point usually corresponds to one character, but not always. For example,
#' an u with a umlaut might be represented as a single character or as the
#' combination a u and an umlaut.
#'
#' @inheritParams str_detect
#' @return A numeric vector giving number of characters (code points) in each
#'    element of the character vector. Missing string have missing length.
#' @seealso [stringi::stri_length()] which this function wraps.
#' @export
#' @examples
#' str_length(letters)
#' str_length(NA)
#' str_length(factor("abc"))
#' str_length(c("i", "like", "programming", NA))
str_length <- function(string) {
}

When you roxygenise() (or devtools::document()) your package these comments will be automatically transformed to the .Rd that R uses to generate the documentation you see when you type ?str_length.

Learn more

To get started, first read vignette("roxygen2"). Then read more about the specific package component that you want to generate:

  • Start with vignette("rd") to learn how document your functions with roxygen2.

  • vignette("rd-other") discusses how to document other things like datasets, the package itself, and the various pieces used by R's OOP systems.

  • vignette("rd-formatting") gives the details of roxygen2's rmarkdown support.

  • vignette("reuse") demonstrates the tools available to reuse documentation in multiple places.

  • vignette("namespace") describes how to generate a NAMESPACE file, how namespacing works in R, and how you can use roxygen2 to be specific about what your package needs and supplies.

  • For the Collate field in the DESCRIPTION, see ?update_collate().

Copy Link

Version

Install

install.packages('roxygen2')

Monthly Downloads

194,711

Version

7.3.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

January 22nd, 2024

Functions in roxygen2 (7.3.1)

roxy_block

Blocks
roxy_tag

roxy_tag S3 constructor
roxygenize

Process a package with the Rd, namespace and collate roclets
roclet

Build a new roclet.
tag_parsers

Parse tags
tags-rd-other

Tags for documenting datasets and classes
tags-rd-formatting

Tags related to markdown support
roclet_find

Create a roclet from a string.
roxygen2-package

roxygen2: In-Line Documentation for R
roxy_tag_rd

Generate Rd output from a tag
tags-index-crossref

Tags for indexing and cross-references
tags-namespace

Tags for managing the NAMESPACE
vignette_roclet

Re-build outdated vignettes
object

Constructors for S3 object to represent R objects.
object_format

Default format for data
tags-rd

Tags for documenting functions
tags-reuse

Tags that help you reuse documentation
rd_roclet

Roclet: make Rd files
tags_list

Access metadata about built-in tags
parse_package

Parse a package, file, or inline code
update_collate

Update Collate field in DESCRIPTION
RoxyTopic

A RoxyTopic is an ordered collection of unique rd_sections
namespace_roclet

Roclet: make NAMESPACE
load

Load package code
markdown-test

Dummy page to test roxygen's markdown formatting
is_s3_generic

Determine if a function is an S3 generic or S3 method.
load_options

Load roxygen2 options
double_escape_md

Check markdown escaping
escape_rd_for_md

Escape Rd markup, to avoid interpreting it as markdown
markdown_pass1

Expand the embedded inline code
escape_examples

Escape examples
roc_proc_text

Process roclet on string and capture results.
rd_section

Construct an rd_section object