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
17
votes
1 answer

Exclude function from R package manual

I'm writing an R package, and I'm documenting all of my functions with roxygen2. However, I do not want all functions to appear in the manual of the package. How can I specify which functions should appear in the package manual, or which ones should…
Benjamin Allévius
  • 817
  • 1
  • 7
  • 14
17
votes
2 answers

Roxygen and suggested packages

I am developing a package with roxygen2, that includes a number of lattice based visualizations. These are nice but not necessary for using the package, and therefore lattice is listed in the Suggests: section of the DESCRIPTION file rather than the…
Backlin
  • 14,612
  • 2
  • 49
  • 81
16
votes
1 answer

Is it possible to @inheritParams from a function within another package?

I wrote an importer for an obscure TSV format, which I want to package and document: https://github.com/katrinleinweber/MWX-import/commits/package The importer function passes a renamed skip_lines parameter to utils::read.table so I would like to…
Katrin Leinweber
  • 1,316
  • 13
  • 33
16
votes
3 answers

do not show function help document in building R package by roxygen2

I am using devtools to build R package, and there are some functions that are NOT designed to be visible to end-users. However, since these functions involve calling C codes by .Call, so that I have to write @useDynLib above the function for…
alittleboy
  • 10,616
  • 23
  • 67
  • 107
15
votes
1 answer

Error Objects in \usage without \alias in documentation object from R CMD Check

I have written a small package for my own use, and using devtools everything has gone very well. However, I tried to run R CMD Check on it, and got a number of errors, seemingly because my usage and examples use functions from base R that aren't in…
PaulHurleyuk
  • 8,009
  • 15
  • 54
  • 78
14
votes
1 answer

How to add class-specific alias without generic alias using Roxygen2?

A simple example is that I have created an extension to show, which is a S4 base method. I don't want to cause a disambiguation fork by re-documenting show in my package, and I also want to consolidate the documentation of my extension to show in…
Paul 'Joey' McMurdie
  • 7,295
  • 5
  • 37
  • 41
14
votes
1 answer

"Could not find function" in Roxygen examples during CMD check

I'm running a CMD check on a package in RStudio, part of which analyses the @examples in the inline Roxygen documentation. I'm getting this error: checking examples ... ERROR Running examples in ‘packagename-Ex.R’ failed The error most likely…
Serenthia
  • 1,222
  • 4
  • 22
  • 40
14
votes
3 answers

Is it possible to write package documentation using non-ASCII characters with roxygen2?

Is it possible to write documentation in R using non-ASCII characters (such as å, ä, ö) using roxygen2? I'm asking because I am writing an package with internal functions in Swedish. I have use the following code using roxygen to write…
FilipW
  • 1,412
  • 1
  • 13
  • 25
14
votes
3 answers

Data not exported from namespace in R

I've set up and been regularly updating my R package to GitHub following Hadley's extensive documentation about Devtools, Roxygen2 etc., on my laptop. Yesterday I decided to use my main PC instead and am now looking to push changes up to GitHub. I…
dez93_2000
  • 1,730
  • 2
  • 23
  • 34
14
votes
3 answers

How do I use roxygen to document a R package that includes a function with the same name?

I'm learning to use roxygen. I see that the rd vignette advocates using "_PACKAGE" to indicate that I'm creating package documentation, and says "This also works if there’s already a function called pkgname()." I've also seen the R packages book…
bheavner
  • 519
  • 1
  • 4
  • 20
14
votes
1 answer

R render Rd using roxygen2 without roxygen2 version

Auto-documentation feature using roxygen2, while it is great and useful, it is annoying on every change of roxygen2 package version. It updates all my documentation files by putting roxygen2 version inside each file. See below. % Generated by…
jangorecki
  • 16,384
  • 4
  • 79
  • 160
13
votes
1 answer

How to cross-reference an equation in an R help file/roxygen2

I'm in the process of documenting some of my functions for an R package I'm making. I'm using roxygen markup, though that is largely irrelevant to my question. I have put equations into my documentation using \deqn{...}. My question is: Is there a…
mathematical.coffee
  • 55,977
  • 11
  • 154
  • 194
13
votes
1 answer

"API rate limit exceeded" when trying to install local R package using devtools::install()

Package development beginner here! I'm trying to turn some code into a local R package for the very first time. I made a package using usethis::create_package(), added documentation using devtools::document(). Now, after playing around with it for…
labracadabrat
  • 241
  • 2
  • 11
13
votes
0 answers

how do I use @importFrom so that it applies to a whole R package?

automated data analysis workflows I have the following code in my packagename.R file in the packagename folder. I know I am going to use certain functions from other packages routinely, so I want to import them once instead of typing them out all…
wdkrnls
  • 4,548
  • 7
  • 36
  • 64
13
votes
1 answer

R: roxygen2, imported packages do not appear in namespace

I have a file: import_packages.r in my project, containing following: #' @import reshape2 #' @import ggplot2 #' @import DESeq2 #' @import geneplotter #' @import survcomp #' @import gplots #' @import pheatmap #' @import RColorBrewer When I do…
Alina
  • 2,191
  • 3
  • 33
  • 68