| Title: | Markdown Reference and Site Documentation for R Packages |
|---|---|
| Description: | Renders the Rd documentation of an R package as plain 'Markdown': one file per topic, an index, and one file with the full reference. The output reads well on 'GitHub' and works as context for a large language model. It reads an installed package with tools::Rd_db(), or a source package from its man/*.Rd files without installation. |
| Authors: | Richard Aubrey White [aut, cre], Peter Czerner [aut, cph] (original pkgmd code), Folkehelseinstituttet [cph] |
| Maintainer: | Richard Aubrey White <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2026.10.12 |
| Built: | 2026-10-12 15:55:03 UTC |
| Source: | https://github.com/niphr/csdocs |
Reads 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).
build_reference( package = ".", output_dir = NULL, overwrite = TRUE, include_private = TRUE )build_reference( package = ".", output_dir = NULL, overwrite = TRUE, include_private = TRUE )
package |
Name of an installed package, or a path to a local
package source directory. Defaults to |
output_dir |
Target directory for the generated |
overwrite |
If |
include_private |
If |
package accepts two kinds of input:
the name of an installed package, e.g. "dplyr" - Rd data is
read via tools::Rd_db();
a path to a local package source directory, e.g. "." or
"../myotherpkg" (detected by the presence of a DESCRIPTION file
at that path) - Rd data is read directly from man/*.Rd, falling
back to a live roxygen2::parse_package() parse if man/ is
missing or empty. This mode does not require the package to be
installed.
Invisibly, the path to output_dir.
## Not run: # 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) ## End(Not run)## Not run: # 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) ## End(Not run)
Writes the reference, every R Markdown vignette and a front page as Markdown files that read as linked pages on github.com. The output has this layout:
README.md: the front page. It shows the package name, the
version, the source commit when known, a list of articles and a link
to the reference.
reference/: the output of build_reference().
articles/: one <name>.md file for each vignettes/*.Rmd file,
with its figures in a folder beside it.
build_site(package = ".", output_dir, overwrite = TRUE)build_site(package = ".", output_dir, overwrite = TRUE)
package |
Path to a package source directory, which MUST contain a
|
output_dir |
Target directory. Created if it does not exist. |
overwrite |
If |
build_site() copies the whole vignettes/ folder to articles/, so
images and other assets stay beside the articles. It renders each .Rmd
file there with rmarkdown::github_document(html_preview = FALSE), in a
new environment whose parent is the global environment. Then it deletes
the copied .Rmd files and any .Rmd.orig files.
The front page lists each article under the title field of its YAML
header, or under its file name when the header has no title. The commit
comes from the GITHUB_SHA environment variable, else from
git rev-parse HEAD in package. The front page shows its first 7
characters. When neither source gives a commit, the front page omits it.
Install the package before you call build_site() when a vignette
calls library() on it. The vignettes run against the installed
version, and the reference reads the source.
build_site() does not render Quarto (.qmd) vignettes. It copies them
unrendered and gives a warning that names each one.
Invisibly, the path to output_dir.
## Not run: csdocs::build_site(".", output_dir = "docs-build") ## End(Not run)## Not run: csdocs::build_site(".", output_dir = "docs-build") ## End(Not run)
Returns the same Markdown content that build_reference() writes to
_full_reference.md - every topic rendered and concatenated into one
string - without writing anything to disk. Meant for programmatic
consumption, e.g. an LLM agent that wants a package's complete
reference injected directly into its context in one call.
get_documentation(package = ".", include_private = FALSE)get_documentation(package = ".", include_private = FALSE)
package |
As in |
include_private |
If |
A single string: the package's full reference documentation in Markdown.
## Not run: # Installed package: docs <- csdocs::get_documentation("dplyr") # Development package, not installed: docs <- csdocs::get_documentation(".") ## End(Not run)## Not run: # Installed package: docs <- csdocs::get_documentation("dplyr") # Development package, not installed: docs <- csdocs::get_documentation(".") ## End(Not run)