Rd2roxygen: Convert all the Rd files of a package to roxygen comments

View source: R/rd2roxygen.R

Rd2roxygenR Documentation

Convert all the Rd files of a package to roxygen comments


This function takes a package root directory, parses all its Rd files under the man directory and update the corresponding R source code by inserting roxygen documentation in to the R scripts.


Rd2roxygen(pkg, nomatch, usage = FALSE)



the root directory of the package


the file name (base name only) to use when an object in the Rd file is not found in any R source files (typically this happens to the data documentation); if not specified, the default will be ‘pkg’-package.R


logical: whether to include the usage section in the output


NULL (but the process of conversion will be printed on screen)


ESS users may use options(roxygen.comment = "##' ") to ensure the generated roxygen comments begin with "##' ", which is the default setting in Emacs/ESS.

Re-run this function on a package will remove the previous roxygen comments before functions in R scripts.


Yihui Xie <http://yihui.org>


## a demo package
pkg = system.file("examples", "pkgDemo", package = "Rd2roxygen")
file.copy(pkg, tempdir(), recursive = TRUE)  # copy to temp dir first
od = setwd(tempdir())

## take a look at original R scripts

options(roxygen.comment = "##' ")

## convert Rd's under man to roxygen comments
Rd2roxygen(file.path(tempdir(), "pkgDemo"))

file.show("pkgDemo/R/foo.R")  # what happened to foo.R and bar.R?

setwd(od)  # restore working directory

Rd2roxygen documentation built on Aug. 10, 2022, 1:09 a.m.