Expand description
Shared utilities for R class wrapper generation.
This module provides abstractions to reduce duplication across the 5 class system generators (Env, R6, S3, S4, S7). Each class system has different R idioms but shares common patterns:
- Class-level roxygen documentation
- Constructor generation
- Instance method iteration with
.Call()building - Static method handling
- Return strategy application
§Architecture
ParsedImpl
│
├─▶ ClassDocBuilder → roxygen header lines (#' @title, @name, etc.)
│
└─▶ MethodContext[] → pre-computed method data for each method
│
└─▶ ClassFormatter::format_constructor()
└─▶ ClassFormatter::format_instance_method()
└─▶ ClassFormatter::format_static_method()Structs§
- Class
DocBuilder - Builder for class-level roxygen documentation header.
- Method
Context - Pre-computed context for a method, holding all data needed for R wrapper generation.
- Method
DocBuilder - Builder for method-level roxygen documentation.
Traits§
- Parsed
Impl Ext - Extension trait for
ParsedImplto iterate over methods asMethodContext.
Functions§
- build_
match_ 🔒arg_ prelude - Build R prelude lines that validate
match_arg/choices/several_okparameters before the.Call(). - build_
method_ 🔒precondition_ checks - Build the R-side precondition guard lines for a parameter list, given
its per-param map (match_arg/choices skips,
inherits/not_inherits/no_nachecks, each parameter’s ownpreconditionsdecision), whethercoerceis active for the whole method, and the method’s and impl block’spreconditions/no_preconditions(method_level,impl_level). Each parameter keeps its type-derived checks ascrate::r_preconditions::resolve_type_checksdecides, under the crate default and theno-preconditions-defaultfeature; the named checks stay either way. - choice_
param_ 🔒doc_ map - Build the R-formal → auto-generated
@paramtext map for a method’s choice params: the write-time placeholder for amatch_argparam (the wrapper writer renders it from the enum’sMatchArg::CHOICES, #210), the literalOne of "a", "b".line for achoices(...)param (ParamAttrs::literal_choices_doc, the same text a standalone function gets). Pass toMethodDocBuilder::with_choice_param_docsin each class generator. - class_
ref_ 🔒or_ verbatim - Return a
.__MX_CLASS_REF_<name>__placeholder (for bare identifiers) so the resolver can look up the actual R class name at wrapper write time, ornameverbatim (for namespaced / non-identifier strings). - describe_
params_ 🔒lines - The documentation body of a method block that has no
\usage(env methods): the author tagsforwardaccepts, verbatim, then one\describe{}list with the author’s@paramitems followed by the choice items ofgenerated_params. A formal without choice text gets no item (nothing in\usageasks for one), and no@paramline is emitted: with no usage entry to match, roxygen2 would write an\argumentsentry thatR CMD checkreports as “Documented arguments not in \usage”. - effective_
r_ 🔒defaults - Effective R-formal defaults for a method.
- emit_
s3_ 🔒generic_ guard - Emit the conditional S3 generic guard for a given generic name.
- generated_
params 🔒 - The formals of
r_paramsthatdoc_tagsleaves undocumented, each with its choice text fromchoice_docs(the write-time placeholder of amatch_argparameter, the literal line of achoices(...)one), orNonefor a formal that has none. Skips.mx_self,.ptrand..., and yields nothing when the tags take the arguments from another topic (roxygen::params_documented_elsewhereagainstpage, #1590). The class page default a builder appends is not indoc_tags, and an author@rdnamenamingpageis the same page, so neither suppresses them. - instance_
formals 🔒 - Prefix an instance receiver and append only missing dispatch dots. Shared by inherent and trait wrapper contexts; explicit Dots keeps its place.
- is_
bare_ 🔒identifier - Check whether
sis a bare R identifier (only[A-Za-z_][A-Za-z0-9_]*). - match_
arg_ 🔒skip_ set - The R formals of the parameters that are validated by R’s
match.arg()and therefore don’t need type-check preconditions generated for them. Shared byMethodContextandTraitMethodContext. - push_
param_ 🔒filler - Push one
#' @param name textline pergenerated_paramsentry: the choice text for a choice parameter,(undocumented)otherwise (soR CMD checkcodoc sees every formal in\usagedocumented). - should_
export_ 🔒from_ tags - Determine whether a class or method should be
@export-ed.