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

Rstudio not generating .Rd files

I had created an R package several months using Rstudio. All I had to was to select File->New Project ->New Directory ->R package and then add R files to the project after specifying project name. When I clicked "Create Project" the R package…
Tinniam V. Ganesh
  • 1,979
  • 6
  • 26
  • 51
0
votes
0 answers

R: DESCRIPTION-file fails to import the dependencies

still having some problems with creating R-package. I'm trying to organize some import dependencies to my package and this seems to go wrong. I setup my DESCRIPTION-file as shown below and when i call the first method i get an error. It seems like…
Lycone
  • 650
  • 9
  • 18
0
votes
1 answer

R documenting S4 generic does not show usage

This question was already asked in this stackoverflow question but the accepted answer (download the S4 branch from the author's repository) does not work for me and I think there might be a better way to achieve the same. I have the following in my…
Pablo
  • 328
  • 2
  • 16
0
votes
0 answers

S4 Method Documentation

I am getting a build warning: Undocumented S4 methods: generic 'plot' and siglist 'cd.fit,missing' and can't figure out what isn't documented. Here is what the method documentation looks like: ##' Something here ##' @param a bunch of paramter…
scottyaz
  • 722
  • 7
  • 18
0
votes
0 answers

make S3 generic function name available when adding new method, roxygen2

I wrote a new S3 method in an R package, for a generic function 'NSE' from package 'hydroGOF', and I am unsure how to (let roxygen2) formulate the NAMESPACE. Here is an example. 'NSE' has two required arguments, 'sim' and 'obs'. #' @export #'…
renec
  • 1
  • 1
0
votes
0 answers

Problems documenting S3 generic when checking R package

Despite a lot of documentation and questions that I have already read in this forum, I still haven't been able to properly document my S3 generics. My code works, and I have successfully used my package, and even successfully tested it with friends.…
Derek Corcoran
  • 3,930
  • 2
  • 25
  • 54
0
votes
1 answer

Generating a the package documentation file

I'm in the process of putting together an R package, using devtools. It seems that most packages on CRAN has a documentation file that covers all documented functions. How do I build this? I have pkgname.R, like so: #' _PACKAGE #' @encoding…
0
votes
1 answer

S3 Methods not being explicitly exported

When I dispatch on the top level object, all the functions export to the namespace. Everything works as I would expect it to. myfun <- function(obj) { UseMethod("myfun",obj) } #' @export myfun.this <-…
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
0
votes
1 answer

roxygen2 docstrings for Reference Classes overriding base class

I have an abstract base class that looks like this: #' An Abstract Base Class Filter <- setRefClass( Class = "Filter", methods = list( train = function(x) { "Override this method to train any associated parameters for the filter on…
John Greenall
  • 1,670
  • 11
  • 17
0
votes
1 answer

Writing 'as.data.frame' method for custom S3 objects

In many variants, similar questions have been asked many times ... but i do not find a clear advice about: "exporting S3 methods as functions" I wrote a custom S3 class with roxygen2, call it 'my_item'. This is the constructor function: my_item…
hute37
  • 197
  • 2
  • 8
0
votes
1 answer

Error during build and reload in R

I am roxygenizing a package I am making in R. The script is #' HandyTools #' #' Check if required packages are installed or not and installs them if not #' @param packageList - a list containing the required package names #' #' @examples #'…
j1897
  • 1,507
  • 5
  • 21
  • 41
0
votes
0 answers

How to create a roxygen documentation?

I begin to learn how to use roxygen, so I found this post by @hadley and go down to this tutorial page: http://r-pkgs.had.co.nz/man.html For doing the first example, I created a new project and a new test.R file. I copied these example code to…
xirururu
  • 5,028
  • 9
  • 35
  • 64
0
votes
1 answer

R function only fails when called via my package

I am creating a package for work (called mypackage) and have a function I would like to include in it. This function seems to work perfectly fine when I call it like this: myFunction() But, it fails when I call it like this:…
statsNoob
  • 1,325
  • 5
  • 18
  • 36
0
votes
0 answers

Is there a way to create Roxygen2 source code from documentation (.rd)?

I have to modify a package in R that i wrote time ago and i would like to add easily more functionalities using roxygen2. How can i translate the .rd files in my source code? Help is much appreciated
Garini
  • 1,088
  • 16
  • 29
0
votes
1 answer

R: Custom packages installs, loads fine, but functions are not there

There is a previous question here with much the same issue, but I don't understand the solution given and it is not given as an answer, only in the comments. Hence the need for a new question. I have followed this guide to create a new R package. To…
CoderGuy123
  • 6,219
  • 5
  • 59
  • 89