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
24
votes
3 answers

why roxygen2 does not automatically update "Imports" in DESCRIPTION file?

I am trying to follow closely @hadley's book to learn best practices in writing R packages. And I was thrilled to read these lines about the philosophy of the book: anything that can be automated, should be automated. Do as little as possible by…
elikesprogramming
  • 2,506
  • 2
  • 19
  • 37
24
votes
7 answers

Possible to create Rd help files for objects not in a package?

I am using Rstudio to streamline Sweave and R for data analyses that I will share with other analysts. In order to make the coding of variables crystal clear, it would be great to have something like a help file so they can call ?myData and get a…
AdamO
  • 4,283
  • 1
  • 27
  • 39
24
votes
4 answers

How to export S3 method so it is available in namespace?

I am creating a package and for S3 methods I export them using ##' @method predict myclass ##' @export predict.myclass <- function(object,...) { } Now when I load the package, then predict works on object of the class myclass, but function…
mpiktas
  • 11,258
  • 7
  • 44
  • 57
23
votes
1 answer

adding useDynLib through Roxygen

I am converting my packages to use roxygen documentation, through the roxygen2 package. Now my package does not load and I think that is is because of the missing useDynLib(mypackage) call missing from the NAMESPACE file. How do I get this…
Andrew Redd
  • 4,632
  • 8
  • 40
  • 64
23
votes
2 answers

R CMD check warning: Functions/methods with usage in documentation object ... but not in code

I am writing a package but one persistent R CMD check warning prevents me from finishing the package and posting it to CRAN. I use roxygen2 for inline documentation, although that possibly isn't the root cause of the error. If you know what to do to…
Andrie
  • 176,377
  • 47
  • 447
  • 496
23
votes
2 answers

Documenting two S3 methods in the same file with Roxygen

I have two methods for an S3 generic (defined in another package) that are closely related and so I wanted to document them in the same Rd file. However, when I document their arguments separately, I get a warning from R CMD check about "Duplicated…
Brian Diggs
  • 57,757
  • 13
  • 166
  • 188
22
votes
2 answers

Exporting non-S3-methods with dots in the name using roxygen2 v4

Since roxygen2 version 4.0.0, the @S3method tag has been deprecated in favour of using @export. The package now tries to detect if a function is an S3 method, and automatically adds the line S3method(function,class) to the NAMESPACE file if it think…
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
21
votes
2 answers

Citing articles in R package using roxygen2 and BibTeX?

I'm using roxygen2 as a tool for documenting my R package, and I found that there is a @references tag in roxygen2, but that seems to only accept free form text. I found some presentation about roxygen which has tags @bibliograph and @cite, but am I…
Jouni Helske
  • 6,427
  • 29
  • 52
20
votes
1 answer

documenting dataset with roxygen2

I'm trying to document some datasets in an R package using roxygen2. Considering just one of these: I have mypkg/data/CpG.human.GRCh37.RDa which contains an object called CpG.human.GRCh37 and a file called: mypkg/R/cpg-data.R, which contains: #'…
drmjc
  • 659
  • 1
  • 6
  • 10
20
votes
2 answers

Can R help manuals have latex math in them?

I am working on an R package and I am using the package Roxygen2 to write the help manuals for my R functions. What I would like to know is if it is possible to use latex for math equations in the manual pages? For example, if I had a function…
RustyStatistician
  • 989
  • 3
  • 14
  • 25
19
votes
2 answers

How to display the elements of a returned list in Roxygen?

I can do this easily with input parameters by having multiple lines of @param by doing as such: #' @param var1 This is for x #' @param var2 This is for y #' @param var3 This is for Z But how do you do that for the elements of a list you are…
TomNash
  • 3,147
  • 2
  • 21
  • 57
19
votes
4 answers

How to extend S3 method from another package without loading the package

I am developing a package which has the function forecast.myclass. I want that function to work nicely with forecast package. I.e. when forecast package is loaded the code forecast(object) should call forecast.myclass from my package. Since I need…
mpiktas
  • 11,258
  • 7
  • 44
  • 57
18
votes
2 answers

Reference package vignettes with Roxygen2

So, I'd like to reference one of my package vignettes inside the roxygen2 comments of a function but I'm having a hard time understanding how to do it. More generally, how do we reference documents inside /inst/doc? E.g. I'd like to reference…
StevieP
  • 1,569
  • 12
  • 23
17
votes
2 answers

Documenting R6 classes and methods within R package in RStudio

I am struggling with the documentation of an R6 class and its methods. My goal is to get the autocompletion in RStudio for the methods. At the moment, I only get the name of the method but no the help information I normally get using roxygen2…
drmariod
  • 11,106
  • 16
  • 64
  • 110
17
votes
1 answer

Preview development R documentation

I'm writing my first R Package using devtools and roxygen2 in the RStudio IDE. The problem I have is related with previewing the .Rd files I get when I "roxygenize" the .R files. I'm using devtools::document() in order to get the .Rd files, but when…
Servadac
  • 170
  • 8
1 2
3
42 43