Skip to content

Instantly share code, notes, and snippets.

@Shians
Last active August 9, 2019 07:43
Show Gist options
  • Select an option

  • Save Shians/0f2657d9667fca7277ebf3aa3fc2187b to your computer and use it in GitHub Desktop.

Select an option

Save Shians/0f2657d9667fca7277ebf3aa3fc2187b to your computer and use it in GitHub Desktop.
Roxygen2 Tags

This gist is a summary of roxygen2 tags, see roxygen2 docs for source of information.

Header Section

The initial three sections are automatically placed into title, description and details fields of the documentation. The details field is optional.

#' Title goes here
#'
#' Description goes here
#'
#' Details go here (optional)
my_func <- function(x) { }

Functions

  • @param name description: name of an argument and a description of the argument.
  • @examples: example code showing how the function is run. Within @examples the code can be wrapped with the folowing tags:
    • \dontrun{} show code in help file but do not run during example() calls or checks.
    • \donttest{} show code in help file and run during example() calls but not checks.
    • \dontshow{} run the code during checks but do not show in help file. Used for testing, avoid in favour of proper unit tests.
  • @return description: description of the return value.

S3 Methods

Methods in S3 will be automatically parsed, unless there is ambiguity arising from examples such as all.equal.data.frame() which may be interpreted as the all() method for a equal.data.frame class.

  • @method class function: disambiguate classes and methods. For the above example, @method all.equal data.frame.

S4 Objects

  • @slot name description: name of a slot and a description of the slot.

S4 Methods

  • @rdname name: name of the help file in which to describe the S4 method
  • @describeIn name: name of the help file in which to describe the S4 method

Datasets

  • @format description: description of the data format containing the dataset
  • @source description: description of the source of the data, can use \url{} as in @source \url{link.to.source.com}.

Packages

It's good to have documentation for a package itself accessible through ?pkgname, in addition to all its functions and datasets. Title and description are inheritied from the DESCRIPTION file, so additional information should be supplied through @details.

#' @details
#' Information about how to use the package
#' @keywords internal
"_PACKAGE"
  • @details: details section describing how to use the package
  • @keywords internal: hide the documentation from the documentation index.

"_PACKAGE" allows this documentation to be accessed through ?pkgname and package?pkgname.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment