Expand description
Parser for R documentation (.Rd) files.
Rd is a LaTeX-like documentation format used by R packages. Each .Rd file
in a packageโs man/ directory documents one or more R objects (functions,
datasets, classes, etc.).
This module implements a metadata-first parser: it reliably extracts the
structural sections needed for help() lookup, topic resolution, and
example extraction, without attempting full GNU-R-compatible Rd rendering.
The parser is a hand-written stateful lexer that handles:
- Rd commands (
\name{},\title{}, etc.) - Nested brace groups
- Escaped characters (
\%,\{,\},\\) - Comment lines (starting with
%) #ifdef/#ifndef/#endifpreprocessor directives (treated as text)\dontrun{},\donttest{},\dontshow{}blocks in examples
Structsยง
- RdDoc
- A parsed R documentation file.
- RdHelp
Index - An index of Rd documentation, mapping topic aliases to parsed docs.
- RdIndex
Entry - A single entry in the help index.
- RdParser ๐
- Stateful parser for Rd files.
Enumsยง
- RdError
- Errors that can occur when parsing an Rd file.
Functionsยง
- clean_
examples ๐ - Clean examples text: strip comment-only lines (starting with
%) and trim leading/trailing blank lines. - clean_
text ๐ - Clean section text: trim leading/trailing blank lines, normalize internal paragraph breaks (double newlines) while preserving single newlines for line structure.
- clean_
usage ๐ - Clean usage text: preserve line structure but trim each line.
- escape_
rd ๐ - Escape text for inclusion in Rd markup.
- escape_
rd_ ๐usage - Escape text for Rd usage/examples blocks (R code).
- normalize_
whitespace ๐ - Normalize whitespace: collapse runs of whitespace (including newlines) into single spaces, then trim.