Skip to main content

Module rd

Module rd 

Source
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 / #endif preprocessor directives (treated as text)
  • \dontrun{}, \donttest{}, \dontshow{} blocks in examples

Structsยง

RdDoc
A parsed R documentation file.
RdHelpIndex
An index of Rd documentation, mapping topic aliases to parsed docs.
RdIndexEntry
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.