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

How to `\link{}` to a specific section of an Rd file with Roxygen2?

Say I want to link to the "Details" section of my documentation for function foo, what do I do? \link{foo:Details} doesn't appear to work, so what is the right command?
mchen
  • 9,808
  • 17
  • 72
  • 125
30
votes
3 answers

Making an R package PDF manual using devtools

I am making an R package using devtools and roxygen2. I can get a PDF manual using R CMD but I am really curious as to whether this can be done using devtools. devtools' build(), check(), install() all don't make a PDF manual. Is this tied to making…
a1b2d3d4
  • 301
  • 1
  • 3
  • 3
30
votes
1 answer

Using Roxygen2 Template tags

Could someone provide an example of how to properly use the Template Tags in Roxygen2. I have tried to do the most obvious thing (to me): In my packageName-package.R file: #' [... other Roxygen blocks ...] #' #' @templateVar testTemplateTag…
politicalEconomist
  • 1,041
  • 1
  • 14
  • 19
29
votes
4 answers

Keyboard shortcut for inserting roxygen #' comment start

This question might be over-answered but I could not find one. Basically I am using RStudio and the keyboard shortcut cmd + shift + c for inserting comments. Is there an other combination to insert directly the roxygen tags #' ? Or a way to modify…
ClementWalter
  • 4,814
  • 1
  • 32
  • 54
28
votes
14 answers

'data' is not an exported object from 'namespace:my_package'

I'm writing a function that uses an external data as follow: First, it checks if the data is in the data/ folder, if it is not, it creates the data/ folder and then downloads the file from github; If the data is already in the data/ folder, it reads…
Igor
  • 913
  • 1
  • 8
  • 18
27
votes
2 answers

roxygen2 not fully updating DESCRIPTION file

I'm making my first package rlandscape, using Roxygen2 and trying to follow the plain Roxygen vignette since Roxygen2 doesn't have one. As in the vignette (page 3), I created a file called rlandscape-package.R that contains nothing but package…
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
27
votes
3 answers

Importing two functions with same name using roxygen2

I'm a maintainer of a CRAN package and get the following messages when loading: * checking whether package ‘qdap’ can be installed ... [10s/10s] WARNING Found the following significant warnings: Warning: replacing previous import ‘annotate’ when…
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
26
votes
1 answer

Using roxygen2 to inherit only certain parameters

In roxygen2, one can use the tag @inheritParams to inherit the full set of parameters of another function. But is it also possible to inherit only a certain subset of them? (Excluding the case of inheriting ..., which is adequately handled by…
egnha
  • 1,157
  • 14
  • 22
26
votes
2 answers

Documenting equations with deqn and roxygen

I'm using \deqn{}{} with roxygen2 to document equations for a function in a package. The LaTeX (the 1st argument to deqn) renders fine because white space is ignored in LaTeX equations, but I have a problem with the ASCII (the 2nd argument to deqn)…
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
25
votes
1 answer

How to use @inheritParams on single parameters when multiple parameters match?

I would like to document an R function and inherit individual parameter documentation from other functions when multiple parameter names match. For example, lets say I have the following 2 functions. #' Function 1. #' #' Description of function…
stat_student
  • 787
  • 10
  • 17
25
votes
2 answers

How do you write your package documentation?

I haven't quite figured out a sensible workflow for building packages and writing their documentation. I want as much of the process (and the documentation) as possible to be automatically generated. The obvious way to do this seems to be to use…
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
25
votes
5 answers

What does "Error in namespaceExport(ns, exports) : undefined exports" mean?

When building a package, I got the error Error in namespaceExport(ns, exports) : undefined exports: FooBarBaz What does this mean, and how do I fix it?
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
25
votes
3 answers

Include data examples in developing R packages

I am eager to learn how to incorporate data examples as comments written above the functions, such as: ##' @examples ##' ## Set working directory... ##' ## Load data into R session: ##' data <- system.file("extdata", "data.txt", package="...",…
alittleboy
  • 10,616
  • 23
  • 67
  • 107
24
votes
1 answer

Does roxygen2 6.0.0 now require "@export" in the last line?

Prior to updating to roxygen2 version 6.0.0, it appeared that the package supported using the @export tag not at the bottom of the function header in a package. For instance: #' Title #' @param foo #' @return bar #' #' @export #' #' @seealso Other…
DaveRGP
  • 1,430
  • 15
  • 34
24
votes
2 answers

Bilingual (English and Portuguese) documentation in an R package

I am writing a package to facilitate importing Brazilian socio-economic microdata sets (Census, PNAD, etc). I foresee two distinct groups of users of the package: Users in Brazil, who may feel more at ease with the documentation in Portuguese.…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
1
2
3
42 43