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

How to document functions that call the same function but have different parameters?

I'm writing a package that has an internal function that several other exported functions use, but the exported functions all have different parameters. Here is a simplification of what I mean: general <- function(...) { # do something based on…
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
0
votes
2 answers

Why does using "<<-" in a function in the global workspace work, but not in a package?

I'm creating a package using devtools and roxygen2 (in RStudio), however after I've built the package my function no longer works as intended. Yet, if I load the function's .R file and run the function from there in RStudio, it works perfectly. I've…
grlaer
  • 151
  • 1
  • 3
  • 11
0
votes
0 answers

NA in title of package documentation manual pdf

When I create an R-package using UTF-8 encoding and special characters like ä,ß, etc., they are shown correctly in the description, but if the title of a function contains one, the whole title becomes NA. For example, I create the package…
tover
  • 535
  • 4
  • 11
0
votes
0 answers

Cannot install proprietary R library

I have developed my own R library (called HAM) When I use the install() command from the library roxygen2, the result looks as shown below: * installing *source* package 'HAM' ... ** R ** preparing package for lazy loading Warnung: package 'car' was…
user2157086
  • 525
  • 1
  • 5
  • 20
0
votes
0 answers

devtools::document() seems not to work

Devtools is not building .Rd files in the man directory. git clone https://github.com/az0/mlmeta cd mlmeta Rscript -e 'require(devtools);devtools::document()' This gives > require(devtools);document('mlmeta') Loading required package:…
Andrew
  • 1,619
  • 3
  • 19
  • 24
0
votes
1 answer

How to take data files info to index and how to update a data file in an existing R package properly?

I have written an R package in which the names of the functions are in Turkish. I wanna take that package to CRAN with internalization. I changed all of the Turkish names (of functions, of data sets) to English so that everybody can easily use the…
Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40
0
votes
0 answers

R / devtools / roxygen2 : difficulty creating package

I'm trying to turn this function found here into an R package. I'm following the directions found here. Here are the steps I take: 1) Load required library library(devtools) 2) Go to a new location setwd('C:\\myRpkgs\\') 3) Create…
screechOwl
  • 27,310
  • 61
  • 158
  • 267
0
votes
0 answers

Prevent @family from creating links to S3 methods

Using "roxygen2" I use @family to group together a bunch of S3 generic functions (each with some methods). In generated Rd files the See Also sections contains links not only to generic functions, but also to all defined methods. Is there any way to…
Michał
  • 2,755
  • 1
  • 17
  • 20
0
votes
0 answers

Repetition of Argument Definitions in Roxygen2

I have a package with an S4 object and 10 functions which have the same 10 arguments. I can either just write the same @param for 10 times (as I currently do), or maybe I can just write them once with Roxygen2 in a documentation file. But I'm not…
Miller Zhu
  • 697
  • 1
  • 7
  • 15
0
votes
1 answer

chapters in R reference manual and documentation using roxygen2

Once I've seen a package supporting R program in which his documentation and reference manual was divided into chapters ( they were called by the consecutive letters of the alphabet ) so that an user could see that functions presented by that…
Marcin
  • 7,834
  • 8
  • 52
  • 99
0
votes
0 answers

Issues with \dontrun when using roxygen2

I am using roxygen2 to document my package, however, I cannot use \dontrun to avoid running my example code. Here's what I have done: #' @examples \dontrun { #' x <- myfunc() #' } when W use roxygenize to generate the docuemnt, and use ?myfunc to…
yuez
  • 885
  • 1
  • 8
  • 16
0
votes
1 answer

How to prevent importFrom statements from autodeletion from NAMESPACE file?

My NAMESPACE file is: # Generated by roxygen2 (4.0.1): do not edit by hand export(ARorderG) export(VOBoegmc) export(conddiffG) ................ export(sablon) Upon trying to check the package…
Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40
0
votes
2 answers

Roxygen2 says Error: file already exists .../RcppExports.cpp

I am practicing R package writing with Rcpp, devtools, and roxygen2. However, when I run document("mypkg") under the dev mode, I got the following error: Updating mypkg documentation Loading mypkg Error: file already exists:…
yuez
  • 885
  • 1
  • 8
  • 16
0
votes
2 answers

Make third party library available in my R package

I am developing an R package that uses third party functions available in the Bioconductor package "methyilumi" In the code for my R package at the very beginning I import methylumi with library(methylumi). During the development (I use roxygen2 and…
lucacerone
  • 9,859
  • 13
  • 52
  • 80
0
votes
2 answers

Debugging roxygen2's roxygenize in R

Whilst running the roxygenize() command from the roxygen2 package in R, I get the message: Error in get(fun, mode = "function", envir = parent.frame()) : object '22' of mode 'function' was not found Any ideas how to debug this message would be…
Dave Slanted
  • 145
  • 1
  • 5
1 2 3
42
43