pub struct PackageHelpDb { /* private fields */ }Expand description
A reader over an installed R package’s compiled help database:
help/<pkg>.rdx + help/<pkg>.rdb, plus the sibling help/aliases.rds
and Meta/hsearch.rds files.
The .rdx index is parsed eagerly at PackageHelpDb::open (it’s
small); .rdb records are read on demand by seeking into the .rdb
file, since records are independent and there’s no need to hold the
whole file in memory. help/aliases.rds is parsed lazily, on the first
call to PackageHelpDb::aliases or PackageHelpDb::resolve_alias,
and the resulting index is cached for the lifetime of this reader – a
failed parse is NOT cached, so a transient failure (a missing or
momentarily corrupt file) is retried on the next call rather than
poisoning every subsequent lookup. A duplicated alias resolves to its
LAST occurrence, matching the last-wins semantics of R’s own
list2env()-based alias loader; PackageHelpDb::aliases still
returns every entry, including duplicates, in on-disk order, since
that’s what oracle comparisons against R’s readRDS() expect.
search_index() re-reads Meta/hsearch.rds on every call rather than
caching – it’s read infrequently relative to alias/topic lookups, and
re-reading keeps the API simple and always up to date.
Implementations§
Source§impl PackageHelpDb
impl PackageHelpDb
Sourcepub fn open(pkg_dir: impl AsRef<Path>) -> Result<Self, Error>
pub fn open(pkg_dir: impl AsRef<Path>) -> Result<Self, Error>
Opens <pkg_dir>/help/<pkg>.rdx (+ .rdb), where <pkg> is the
basename of pkg_dir, e.g. /opt/R/4.6.1/lib/R/library/utils.
Library-path discovery (R’s .libPaths()) is out of scope: callers
must supply the installed package directory explicitly.
Sourcepub fn package(&self) -> &str
pub fn package(&self) -> &str
The package name (the basename of the directory passed to
PackageHelpDb::open).
Sourcepub fn topics(&self) -> impl Iterator<Item = &str>
pub fn topics(&self) -> impl Iterator<Item = &str>
Topic names present in the .rdx variables map, in index order.
Sourcepub fn reference_keys(&self) -> impl Iterator<Item = &str>
pub fn reference_keys(&self) -> impl Iterator<Item = &str>
Persistence keys present in the .rdx references map (e.g.
"env::0"), in index order.
Sourcepub fn raw_topic(&self, topic: &str) -> Result<RObject, Error>
pub fn raw_topic(&self, topic: &str) -> Result<RObject, Error>
Raw decoded Rd object for topic: a .rdx variables lookup, a
.rdb record fetch, zlib decompression, and rd_rds::parse.
Sourcepub fn reference(&self, key: &str) -> Result<RObject, Error>
pub fn reference(&self, key: &str) -> Result<RObject, Error>
Fetches a record via the .rdx references map (persistence keys
like "env::0"). Same mechanics as PackageHelpDb::raw_topic,
different key space.
rd-helpdb does not attempt to resolve PERSISTSXP nodes into
environments; this only exposes the raw record a reference key
points at.
Sourcepub fn aliases(&self) -> Result<Vec<(String, String)>, Error>
pub fn aliases(&self) -> Result<Vec<(String, String)>, Error>
alias -> topic map from help/aliases.rds, in on-disk order,
including duplicate aliases if the file has any (see the
struct-level docs for how PackageHelpDb::resolve_alias handles
duplicates).