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

566 questions
310
votes
3 answers

How to properly document S4 class slots using Roxygen2?

For documenting classes with roxygen(2), specifying a title and description/details appears to be the same as for functions, methods, data, etc. However, slots and inheritance are their own sort of animal. What is the best practice -- current or…
Paul McMurdie
  • 6,801
  • 4
  • 32
  • 39
103
votes
4 answers

How to not run an example using roxygen2?

I'm writing a geocoding function right now that relies on having a Bing Maps Key. Obviously I'd rather not publish mine, and the examples fail without one. How do I include an example for users to run manually, but not have it executed during R CMD…
Ari B. Friedman
  • 66,857
  • 33
  • 169
  • 226
91
votes
1 answer

Using roxygen2 and doxygen on the same package?

I have an R package that uses roxygen2. It has some C code in /src, and I have just started working with Doxygen. Are there any ways to combine the documentation, or integrate compiling with roxygen2? Any "best practices" for where to put the C code…
Abe
  • 10,626
  • 12
  • 42
  • 70
80
votes
7 answers

Error in fetch(key) : lazy-load database

I don't know what is going on, everything was working great but suddenly I started to have this error message on the documentation: Error in fetch(key) : lazy-load database '......descopl.rdb' is corrupt I removed almost all my code and build…
Paolo RLang
  • 1,394
  • 1
  • 9
  • 10
76
votes
4 answers

Linking to other packages in documentation in roxygen2 in R

I am wondering it there exists a method to link to function from other package when I'm trying to write a documentation for new package using roxygen2. Something like \link{pck=PACKAGE_NAME, fun=FUNCTION_NAME}?
Marcin Kosiński
  • 7,171
  • 5
  • 45
  • 92
68
votes
1 answer

Pre- or post-process roxygen snippets

Is there some mechanism by which I can transform the comments that roxygen sees, preferably before it does the roxygen->rd conversion? For example, suppose I have: #' My function. Does stuff with numbers. #' #' This takes an input `x` and does…
mathematical.coffee
  • 51,909
  • 10
  • 130
  • 180
59
votes
2 answers

Warning about UTF-8 with roxygen2

I have a problem about UTF-8. After conducting roxygen2::roxygenise() for my package, it showed the warning message 'roxygen2 requires Encoding: UTF-8'. How can I fix it? roxygen2::roxygenise() > Writing NAMESPACE > > Loading ABXTT >…
Lann
  • 695
  • 4
  • 8
58
votes
2 answers

Rd file name conflict when extending a S4 method of some other package

Actual question How do I avoid Rd file name conflicts when a S4 generic and its method(s) are not necessarily all defined in the same package (package containing (some of) the custom method(s) depends on the package containing the generic)…
Rappster
  • 11,680
  • 7
  • 58
  • 113
54
votes
2 answers

How to properly document S4 methods using roxygen2

I've seen some discussions in SO and other places regarding how this should be or will be done in future versions of Roxygen2. However, I am stuck. How should I go about documenting a S4 generic, as well as its methods, using Roxygen2? A working…
Paul McMurdie
  • 6,801
  • 4
  • 32
  • 39
53
votes
2 answers

Multiple functions in one .Rd file

Short version: Can I emulate the documentation of Normal in package stats using roxygen? Long version: I'm working on a package and was trying make the documentation more readable by having a number of functions with common inputs/parameters…
dardisco
  • 4,673
  • 2
  • 33
  • 50
52
votes
2 answers

Roxygen2 - how to properly document S3 methods

I've read the Roxygen2 PDF as well as this site and I'm lost about the difference between @method @S3method @export and how you use these to properly document S3 methods. I worked up the follow example for discussion: 1. How would I properly…
SFun28
  • 32,209
  • 43
  • 123
  • 233
49
votes
1 answer

Does roxygen2 automatically write NAMESPACE directives for "Imports:" packages?

tl;dr version of my question If I want to import packages, do I have to manually write import() directives into my NAMESPACE file? It seems like roxygen2 won't magically do that for me, even if I have them listed as "Imports:" in my…
briandk
  • 6,259
  • 7
  • 33
  • 45
42
votes
4 answers

Can RStudio automatically generate an roxygen template for a function?

Does RStudio support any automated roxygen template creation? In Emacs-ESS, C-x C-o will produce an roxygen template for a function. For example, it will automagically convert this: foo <- function(x,y) x+y into this: ##' .. content for…
David LeBauer
  • 28,793
  • 27
  • 106
  • 180
33
votes
1 answer

roxygen2 manually insert line breaks

I have a function I am trying to document with roxygen2: #' Name of function #' #' Description #' #' @param x The input data #' @param method one of: #' "method1" - very long text here #' "method2" - very long text here #' "method3" - very long…
Zach
  • 27,553
  • 31
  • 130
  • 193
32
votes
2 answers

Is it possible to use R package data in testthat tests or run_examples()?

I'm working on developing an R package, using devtools, testthat, and roxygen2. I have a couple of data sets in the data folder (foo.txt and bar.csv). My file structure looks like this: / mypackage / data * foo.txt, bar.csv / inst …
ldecicco
  • 791
  • 7
  • 13
1
2 3
37 38