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

Create an R package with dependencies

I'm trying to write my first R package. The functions in the package depend on the getURL() function from the RCurl package. I followed the tutorials on: http://r-pkgs.had.co.nz/…
jirikadlec2
  • 1,256
  • 1
  • 23
  • 36
8
votes
3 answers

roxygen2 and RStudio, not creating the documentation for the functions

I am trying to add documentation via roxygen2 in a package. I am able to create the packag successfully and on load able to use the functions too. Here is my understanding of how to do it, I create an empty R-Package project on RStudio and then have…
Avinash
  • 2,521
  • 4
  • 21
  • 35
8
votes
1 answer

Rstudio Roxygen2 @importFrom parsing function header

I am building a package with Rcpp using Rstudio. Everything was working fine until I added the markup for documentation to my function file. I hope I am overlooking something obvious. Here is my R function file: #' @useDynLib tablr #' @importFrom…
Zelazny7
  • 39,946
  • 18
  • 70
  • 84
8
votes
1 answer

Verbatim output in roxygen2 package documentation

I am using roxygen2 from within RStudio to generate package documentation. How do I force the following in the @description section to appear as verbatim fixed-font? SettingID Value RedItem Patient_10574 GreenItem Record_433 …
Dieter Menne
  • 10,076
  • 44
  • 67
8
votes
1 answer

Package .Rd files using roxygen2 package

I have a question about creating an .Rd file for my R package using the roxygen2 package. It is clear to me that, for documenting R functions, I can use C-c C-o in emacs to generate comments above the function, and then fill them out, followed by…
alittleboy
  • 10,616
  • 23
  • 67
  • 107
7
votes
1 answer

Cannot call roxygenize function from Rscript batch file

I am writing a script that uses roxygen2 to automatically roxygenize my package. I'd like it to be executable so that it can be part of a larger script to prepare and install the package, but I cannot make it work with Rscript for some reason. Here…
Erik Shilts
  • 4,389
  • 2
  • 26
  • 51
7
votes
1 answer

Arguments descriptions order in .Rd file when using the roxygen2 tag @inheritParams

Let's say I am writing a small R package including two functions with exaclty the same arguments except one. Here is an example: fct1 <- function(r, K){...} fct2 <- function(r, p, K){...} In my roxygen2 documentation of the first function I use the…
7
votes
1 answer

roxygen2 not documenting a new project

I am trying to document a new R project using roxygen2. I am using roxygen2 version 6.1.1 and desc version 1.2.0. I have tried both the commands roxygen2::roxygenise() and devtools::document() but in both cases I am getting the same error: Updating…
mattyx17
  • 806
  • 6
  • 11
7
votes
0 answers

Exporting and importing S3 method between packages

Disclaimer: I found the solution to this problem when writing this question. But my question now is "How does it work?" I am trying to export S3 method from one package (say pkg.from) and import it into another package (say pkg.to). To export the…
Jan Kislinger
  • 1,441
  • 14
  • 26
7
votes
1 answer

Related functions listed together in R package documentation

I'm developing an R package where the functions fall into logical groups; broadly, "Input", "Data Munging", "Analysis", "Output", "Info", and "Utils". I want my package index to be split into these major headings, in that order, with functions in…
plucky_underdog
  • 326
  • 3
  • 8
7
votes
2 answers

How can I automatically add/update Depends/Imports/Suggests versions in DESCRIPTION?

I like to keep my R packages up to date, and in developing my own package, I want to stick to @Hadley's advice: Generally, it’s always better to specify the version and to be conservative about which version to require. Unless you know otherwise,…
maxheld
  • 3,963
  • 2
  • 32
  • 51
7
votes
2 answers

Why will this R package not install and how can I fix it?

I would like to include a Fortran subroutine in an R package. I have always only built packages using devtools and roxygen (so my knowledge may be pretty limited). I am getting an error that prevents me from the package getting installed after it…
statsNoob
  • 1,325
  • 5
  • 18
  • 36
7
votes
1 answer

Using unbalanced brace in Roxygen/Rd code example

The following MWE fails to compile (via devtools::document()): #' MWE #' #' @examples #' format('{}') # Works #' format('{') # Nope #' format('\{') # Nope #' format('\\{')# Nope format = function (str) {} Regardless of which of the “Nope” lines I…
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
7
votes
2 answers

S4 documentation of "[" with 'missing' arguments

This question is very similar to this question but when I try the answer I receive an addition 'NOTE' following R CMD check. Although it is just a NOTE I would really like to have a completely clean check. * checking Rd line widths ... NOTE Error:…
cdeterman
  • 19,630
  • 7
  • 76
  • 100
7
votes
1 answer

\code{\link{function-name}} in roxygen2

It is my first experience in writing an R-package. I used roxygen2 by following the instructions given in this link http://kbroman.org/pkg_primer/ Everythig is working fine except few things.. there could be a simpler solution to solve the issues,…
ngs06
  • 71
  • 1
  • 2