Questions tagged [roxygen2]

roxygen2 is a Doxygen-like in-source documentation system for Rd, collation, and NAMESPACE. Its primary use is in documenting R functions in-line with the function definition.

roxygen2 is a -like documentation system for packages; allowing in-source specification of Rd files, collation and namespace directives.

The standard way to write R documentation is to create Rd files (R documentation) in the man directory of a package. Rd files are a special file format which closely resembles . They can be processed into a variety of formats, including LaTeX, and plain text. These files describe each object (function, data set, class, generic or method).

With roxygen2, the documentation is written in comments next to each function. Then an R script is used to create the main files.

Example

#' The length of a string (in characters).
#'
#' @inheritParams str_detect
#' @return numeric vector giving number of characters in each element of the
#' character vector. Missing string have missing length.
#' @keywords character
#' @seealso \code{\link{nchar}} which this function wraps
#' @export
#' @examples
#' str_length(letters)
#' str_length(c("i", "like", "programming", NA))
str_length <- function(string) {
  string <- check_string(string)

  nc <- nchar(string, allowNA = TRUE)
  is.na(nc) <- is.na(string)
  nc
}

Advantages of roxygen2:

  • Code and documentation are adjacent

  • roxygen2 dynamically inspects the objects. For example, it can automatically add links to super and subclasses.

  • it takes care of other files that are fiddly or downright painful to maintain by hand: the namespace, collate order in description, and the demos index.

  • it abstracts over the differences in documenting and methods, generics and classes so that they behave basically the same.

The Rd2roxygen package provides a convenient way of converting Rd files to roxygen comments for existing Rd files.

Repositories

Vignettes

Other resources

Related tags

640 questions
13
votes
1 answer

Importing S4 functions from the Matrix package

The Matrix package defines a whole bunch of S4 methods for multiplying matrices, that are dispatched by the S4 generic functions %*%, crossprod, and tcrossprod. How do I import the "%*%" methods, for use in my own package? This piece of code fails…
Zach
  • 29,791
  • 35
  • 142
  • 201
12
votes
1 answer

Displaying numbered list in R package

I'm having trouble getting a numbered list to display in R package help. Here's what I have in roxygen: #' @return #' Bunch of text #' Bunch of text: #' \enumerate { #' \item a #' \item b #' \item c #' } This is displaying without…
matsuo_basho
  • 2,833
  • 8
  • 26
  • 47
12
votes
1 answer

roxygen2 (Version 5.0) incorrectly creates documentation when #' occurs inside function

Consider the following R function definition, to be documented using roxygen2 (version >=5.0) #' @title Test Bug #' @author Daniel Egan #' @param x #' @return Nothing #' @export #' @examples #' testFun(x) testFun <- function(x){ #' Warning1' …
Daniel Egan
  • 826
  • 1
  • 9
  • 22
12
votes
1 answer

Roxygen2 - how to @export reference class generator?

For instance, say I have the following package called Test and I want to export class A: # In /R/Test.R: #' @docType package #' @import methods #' @exportClass A A <- setRefClass("A", methods = list(foo = identity)) However, after building and…
mchen
  • 9,808
  • 17
  • 72
  • 125
11
votes
2 answers

Is it possible/advisable to skip roxygen in favor of roxygen2?

I've recently been pointed towards Roxygen to solve my documentation woes/laziness. But then there's this shiny Roxygen2 which, in my understanding, is somewhat its own thing. Hadley's package tools require the use of Roxygen2, but there doesn't…
Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235
11
votes
1 answer

How to generate README.md from README.Rmd for R package?

Inspecting dplyr shows there's both a README.md file and a README.Rmd file. In the .md file, it says README.md is generated from README.Rmd. Please edit that file It's easy enough to create the .Rmd file, but how then is the .md file generated?…
stevec
  • 41,291
  • 27
  • 223
  • 311
11
votes
3 answers

roxygen Warning: : Missing name

So I'm trying to use roxygen2 to document my code. Unfortunately my supervisor felt it was cluttered having so many functions in the global environment. So I've been told to hide them away in sub environments. This seems to be stopping roxygen…
Peter Clark
  • 161
  • 1
  • 5
11
votes
1 answer

How do you escape "}" using roxygen2?

I'm documenting a function using roxygen2 with an @example. The example has a string that contains a } symbol. #' ... #' @examples #' \dontrun{ #' ## polyline joining the capital cities of Australian states #' pl <-…
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
11
votes
2 answers

How to compress saves in R package build

I'm trying to include a (somewhat) large dataset in an R package. I keep getting the Warning during the check in Rstudio saying that I could save space with compression: * checking data for ASCII and uncompressed saves ... WARNING Note:…
Marc in the box
  • 11,769
  • 4
  • 47
  • 97
11
votes
2 answers

Generate items with multiple arguments in an R documentation via roxygen2

To generate an R documentation file (.Rd) I use the package RStudio/Document option with R 3.0.2, Linux 3.11, devtools 1.5, roxygen2 4.0.1. Objective I want to describe multiple arguments of a function in the documentation file, such as in this…
setempler
  • 1,681
  • 12
  • 20
11
votes
2 answers

How to toggle roxygen comments in Rstudio?

Roxygen comments involve prefixing lines with #'. When writing and testing examples for functions, it's nice to be able to toggle the comments on and off. I could copy and paste the code back and forward to vim and remove or add those comments, but…
Jeromy Anglim
  • 33,939
  • 30
  • 115
  • 173
11
votes
2 answers

Processing example files with roxygen2: backslashes are duplicated (\dontrun becomes \\dontrun)

Actual question How can I avoid that \dontrun{ in a separate file containing examples becomes \\dontrun{ in the respective Rd file after roxygenizing? I did find a workaround, but feel as if I'm maybe just missing something obvious, i.e. some…
Rappster
  • 12,762
  • 7
  • 71
  • 120
10
votes
1 answer

How can I document datasets without adding them to the Collate field?

I'm using roxygen2 to document datasets for a package I'm developing. I know you can use roxygen to document a dataset, but Shane's answer ultimately suggests a hack, which while I'd rather avoid. So, my question is: Where should I put roxygen…
briandk
  • 6,749
  • 8
  • 36
  • 46
10
votes
2 answers

Document a shiny application

Is there any way to generate documentation for a R shiny application? It becomes very hard to maintain a shiny application without documentation. It seems that all the eco-system of tests/documentation is created for an R package structure. Maybe…
agstudy
  • 119,832
  • 17
  • 199
  • 261
10
votes
2 answers

How do I indicate collate order in Roxygen2?

Using roxygen2 documentation with devtools document function automatically generates a Collate: field in the package DESCRIPTION, regardless of whether or not it is necessary to load the package library files in a particular order. I'm working on a…
cboettig
  • 12,377
  • 13
  • 70
  • 113