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
9
votes
2 answers

Error when building R package using roxygen2

I have 2 files, Rfile.R and Cppfile.cpp. Contents in Cppfile.cpp: #include using namespace Rcpp; // [[Rcpp::export]] int CPPF(int k){return ++k;} Contents in Rfile.R: RF<-function(k){return(CPPF(k))} I want to build an R package based on…
user2961927
  • 1,290
  • 1
  • 14
  • 22
9
votes
4 answers

How to configure RStudio package build to work across multiple machines

This question has been asked by another user on the RStudio help page here but has gone unanswered. Basically, I've gone through all the steps: (1) Installed Xcode (2) Downloaded and installed command line tools (3) Installed MacTex (4) Selected…
aaron
  • 6,339
  • 12
  • 54
  • 80
9
votes
1 answer

RStudio: Build and reload adds blank line to 'suggests' field in DESCRIPTION file

whenever I run a Build & Reload from RStudio's Build pane, I get the message ==> Rcmd.exe INSTALL --no-multiarch rwiots Error: contains a blank line and, indeed, when I look, my DESCRIPTION file contains a blank line in the Suggests field. If I…
LondonRob
  • 73,083
  • 37
  • 144
  • 201
9
votes
2 answers

devtools roxygen package creation and rd documentation

I am new to roxygen and am struggling to see how to be able to use it to quickly create a new/custom package. I.e. I would like to know the minimum requirements are to make a package called package1 using devtools, roxygen2/3 so that I can run the…
h.l.m
  • 13,015
  • 22
  • 82
  • 169
8
votes
2 answers

What's the preferred means for defining an S3 method in an R package without introducing a dependency?

I have an R package (not currently on CRAN) which defines a couple of S3 methods of generic functions from other packages (specifically knitr::knit_print and huxtable::as_huxtable). However, they're not a key part of my package, so I'd prefer not to…
Nick Kennedy
  • 12,510
  • 2
  • 30
  • 52
8
votes
2 answers

Renaming and Hiding an Exported Rcpp function in an R Package

Writing an R package, I have a R function that calls a specific Rcpp function. The Rcpp function just serves as a helper function and I do not want to creat a .Rd file for it. My solution so far is to export both functions in the Namespace file…
Cello
  • 91
  • 4
8
votes
2 answers

How to use data within a function in an R package?

I am currently writing a function for an R package. Part of what this function is aimed to do is (a) take data as an input and (b) check one of its columns against a list of acceptable values. These acceptable values are given to me from another…
Mark White
  • 1,228
  • 2
  • 10
  • 25
8
votes
1 answer

In Sublime Text 3, how can I change the comment character?

I like the auto-comment feature Ctrl + /, but I'd like to be able the change the character it uses arbitrarily. I have read many similar questions like this one, but it's not exactly a generic solution. How can I make the comment character use…
nsheff
  • 3,063
  • 2
  • 24
  • 29
8
votes
1 answer

roxygen2 not creating .Rd documentation

I am unable to generate .Rd documentation files for my package using RStudio and Roxygen2. First, let me mention that I have gone through similar problems posted here and have already done the following: Roxygen2 blocks initiated at the beginning…
chainD
  • 83
  • 6
8
votes
2 answers

roxygen2: function not exported to NAMESPACE even after using @export

I am building a package and get an error, saying that a function is not an exported object of the package. In the R script, I have used @export tag to export the function, however when I roxigenise using document() or roxygen() the function is not…
Rospa
  • 131
  • 1
  • 2
  • 6
8
votes
1 answer

No manual pdf created during build of R package

I see that my recent package build no longer creates a manual even though I have not added "--no-manual" to the build settings. I didn't have this problem before - I have recently updated both devtools and roxygen2. Am I missing something? Here is…
Marc in the box
  • 11,769
  • 4
  • 47
  • 97
8
votes
1 answer

Ctrl + Shift + D doesn't run documentation routines

According to the shortcuts help (Alt+Shift+K) the combination Ctrl+Shift+D should run the documentation routines. (This is also said in Section 5.1 of Hadley Wickhams "R packages" http://runsheng.github.io/attachment/r-packages.pdf.) But in my…
Qaswed
  • 3,649
  • 7
  • 27
  • 47
8
votes
1 answer

How do I import a data set (using a roxygen directive)

In a "R" package that uses roxygen2, I use a built-in data set in the example code I provide. When building and checking the package, I get Consider adding importFrom("datasets", "CO2") importFrom("grDevices", "dev.list", "dev.off") I then added…
user52366
  • 1,035
  • 1
  • 10
  • 21
8
votes
3 answers

Add sections to R package's help/documentation

Some R packages (e.g., ggplot2, dplyr,devtools etc.) have alphabetically entitled sections in their help/documentation and a bar of links to those sections (indicated by red arrows in picture below). Other packages (e.g., RcmdrMisc) don't have. …
GegznaV
  • 4,938
  • 4
  • 23
  • 43
8
votes
1 answer

auto set options in own package

it is probably bad style but can I modify options on package loading? E.g. my package should set the following options options(java.parameters = "-Xmx8000m") options(dplyr.width = Inf) lattice.options(default.args = list(as.table =…
ckluss
  • 1,477
  • 4
  • 21
  • 33