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
0
votes
0 answers

Use one environment to run examples using roxygen2

I am writing a package in R that essentially carries out a pipeline. This pipeline has several stages that the user can adapt depending on what they would like to achieve. One of the earliest stages requires running a function that is time…
B.C
  • 577
  • 3
  • 18
0
votes
1 answer

Using Roxygen2 for my utility functions

In my analysis projects (not a package), I usually have utility functions that I source() in different analysis scripts. I've been using the Roxygen2 documentation convention (e.g. starting the documentation with #', which is well supported in…
Heisenberg
  • 8,386
  • 12
  • 53
  • 102
0
votes
0 answers

RStudio does not assign well Help section during building a package

I want to build a Rpackage (RStudio) with this function: #' hex2rgb #' #' Give RGB color code from HEX color code #' #' @param color.vector RGB channels datas from PictureResults #' @return results , the name of the matrix #' …
0
votes
0 answers

error in using github packages in namespace of a package

I have wrote this in descriptive file of a package : Package: Minoo Type: Package Title: Representing some especial graphs Version: 0.1.0 Date: 2017-05-20 Author: Minoo Maintainer: Minoo Description: Functions for demonstrating some especial…
minoo
  • 555
  • 5
  • 20
0
votes
1 answer

R 3.4.0 median methods and roxygen2

I have been asked to update my package Bolstad so that the definition of my S3 median method agrees with the new median generic in R 3.4.0. This means is needs to be able to deal with ... - That is fine, but I also need it to work with roxygen2.…
James Curran
  • 1,274
  • 7
  • 23
0
votes
1 answer

R package help in github gh-pages

Given an R package with a git repo on github, I'm looking for an optimal way to build a github hosted (gh-pages) site from the function documentation within the package (in the form roxygen2 comments). It'd be great to be able to include vignettes…
Dave Braze
  • 441
  • 3
  • 14
0
votes
1 answer

Rcpp::export - exporting only the C++ interface, not the R functions

I do not need roxygen2 and Rcpp to create for me the R functions (or maybe I do?) for the exported C++ functions - is there any way to tell Rcpp::export not to create them? I would be perfectly happy with just .Call-ing them directly. I went through…
Tim
  • 7,075
  • 6
  • 29
  • 58
0
votes
1 answer

How do you import a Python library within an R package using rPython?

The basic question is this: Let's say I was writing R functions which called python via rPython, and I want to integrate this into a package. That's simple---it's irrelevant that the R function wraps around Python, and you proceed as usual. e.g. #…
ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
0
votes
1 answer

R package building error

I am trying to build an R package. I usually run the clean and rebuild command in Rstudio. I am now getting this error message: ==> devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette')) Updating ED2io documentation Loading…
Manfredo
  • 1,760
  • 4
  • 25
  • 53
0
votes
1 answer

R package documentation items params order

I have a package of functions; one function has 22 parameters (including ...). I've recently moved a parameter from being a ... option to being a full parameter, and noticed that even though it's described in the logical order in the function…
dez93_2000
  • 1,730
  • 2
  • 23
  • 34
0
votes
0 answers

R Recompiling documentation & package unload results in lazy-load error

I'm using Roxygen2 to document my R (3.2.4) package and have several windows open as I fix my function @examples: 1) R session where I type devtools::document() to update the Rd file 2) terminal window where I reinstall the package with the updated…
0
votes
0 answers

R custom package - Imported function not found when trying to create NAMESPACE

I'm working on a custom R package, in which I'm using S4 classes and methods. In one of the methods for a custom S4 class in the same file, I'm using the GET() method from the httr package. I tried using roxygen2 to properly set up my NAMESPACE…
jakobus
  • 1
  • 4
0
votes
1 answer

How to insert space in text in a .PDF file created via ".R" -> (roxygen2) ".Rd" -> (R CMD check mypackage) ".PDF"?

I already created many .PDF files via ".R" -> (roxygen2) ".Rd" -> (R CMD check mypackage) ".PDF". Now, I wanted to add a table template in .PDF file of the package (mypackage-manual.pdf): Table: ADF Statistics of the Raw…
Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40
0
votes
1 answer

Markdown and outline an R script

I am using Emacs for an R-script with markdown using oxygen comments. With rmarkdown::render() I produce either a HTML or pdf file. Works great. However, it would be great if I could use outline mode for headings in this file (coloured differently…
arnyeinstein
  • 669
  • 1
  • 5
  • 14
0
votes
2 answers

Can I generate .Rd files without roxygen2 annotations

Is it possible to generate .Rd files for R functions without manually writing roxygen annotations? I know one method is to use prompt() but this does not look at arguments or return values. Can it done through any other command or with RStudio?
Tinniam V. Ganesh
  • 1,979
  • 6
  • 26
  • 51