Documenting Functions with roxygen2
Write @param, @return, @examples, and @export tags for automatic docs.
What Is roxygen2?
roxygen2 lets you write R documentation directly above your function as specially formatted comments starting with #'. When you run devtools::document(), roxygen2 parses these comments and generates man/*.Rd files and updates NAMESPACE automatically.
The Minimal roxygen2 Block
The simplest documentation block needs at least a title and description. The first sentence (up to the first period or blank line) becomes the title. Subsequent paragraphs become the description.
# R/add.R
#
# #' Add two numbers
# #'
# #' Computes the sum of x and y. Both arguments must be numeric.
# #'
# #' @export
# add <- function(x, y) {
# x + y
# }All lessons in this course
- Package Structure with usethis and devtools
- Documenting Functions with roxygen2
- Unit Testing with testthat
- CRAN Submission and Package Maintenance