Need help with roxygen2?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

r-lib
427 Stars 193 Forks Other 2.4K Commits 105 Opened issues

Description

Generate R package documentation from inline R comments

Services available

!
?

Need anything else?

Contributors list

roxygen2

CRAN status R build status Codecov test coverage <!-- badges: end -->

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 devtools from CRAN
install.packages("roxygen2")

Or the development version from GitHub:

install.packages("devtools")

devtools::install_github("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 

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:

  • For
    .Rd
    documentation files, read
    vignette("rd")
    .
  • For the
    NAMESPACE
    , read
    vignette("namespace")
    .
  • For the
    Collate
    field in the
    DESCRIPTION
    , read
    update_collate()
    .

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.