
Generate Markdown reference documentation for a package
Source:R/build_reference.R
build_reference.RdReads the Rd documentation of a package - either installed, or a local
development package that has not been installed - renders it as
Markdown, and writes one .md file per function into output_dir.
Also produces a README.md (index table of all functions) and a
_full_reference.md (every function in one file, meant to be injected
as LLM context, e.g. via @docs/reference/_full_reference.md in Claude
Code).
Arguments
- package
Name of an installed package, or a path to a local package source directory. Defaults to
"."- the common case of runningbuild_reference()from within the package you're documenting.- output_dir
Target directory for the generated
.mdfiles. Created if it does not exist. Defaults to"md-docs", but only whenpackageresolves to a local source directory - for an installed package (e.g."dplyr") there's no similarly obvious default location, sooutput_dirmust be given explicitly.- overwrite
If
TRUE(the default), any.mdfiles already inoutput_dirare removed before writing the new set - this also clears stale files left behind by topics that were since renamed or removed from the package. IfFALSE, aborts instead whenoutput_diralready contains.mdfiles, without touching them.- include_private
If
TRUE(the default), documented topics that aren't part of the package's public API (i.e. not in itsNAMESPACEexports - typically internal helpers documented with@keywords internalrather than@export) are included and marked_(private)_next to their heading, in both the topic file and the index. IfFALSE, such topics are left out of the output entirely. Datasets and other non-callable topics are never treated as private, even though they also aren't inNAMESPACE's exports - see.compute_is_private(). When export status can't be determined at all (a dev package that has never rundevtools::document(), so it has noNAMESPACEfile yet), every topic is treated as public.
Details
package accepts two kinds of input:
the name of an installed package, e.g.
"dplyr"- Rd data is read viatools::Rd_db();a path to a local package source directory, e.g.
"."or"../myotherpkg"(detected by the presence of aDESCRIPTIONfile at that path) - Rd data is read directly fromman/*.Rd, falling back to a liveroxygen2::parse_package()parse ifman/is missing or empty. This mode does not require the package to be installed.
Examples
if (FALSE) { # \dontrun{
# Installed package:
csdocs::build_reference("dplyr", output_dir = "docs/reference")
# Development package, not installed - "." and "md-docs" are both
# defaults, so this is equivalent to just build_reference():
csdocs::build_reference(".", output_dir = "md-docs")
# Public API only, no internal helpers:
csdocs::build_reference("dplyr", output_dir = "docs/reference", include_private = FALSE)
} # }