Expand description
Shared utilities for building R wrapper code.
This module provides builders for constructing R function signatures and call arguments consistently across both standalone functions and impl methods.
§Key Components
RArgumentBuilder: Builds R formals and.Call()arguments from Rust signaturesDotCallBuilder: Formats.Call()invocations with proper argument handlingRoxygenBuilder: Generates roxygen2 documentation tags
§Usage
ⓘ
// Build R function signature
let formals = build_r_formals_from_sig(&method.sig, &r_formals, &defaults);
let call_args = build_r_call_args_from_sig(&method.sig, &r_formals, absent_formals);
// Build .Call() invocation
let call = DotCallBuilder::new("C_MyType__method")
.with_self("self")
.with_args(&["x", "y"])
.build();
// Build roxygen tags
let tags = RoxygenBuilder::new("MyType")
.name("method")
.rdname("MyType")
.export()
.build();Structs§
- DotCall
Builder - Builder for formatting
.Call()invocations in R wrapper code. - Formals 🔒
- The R formal of each parameter of one signature (#1842).
- RArgument
Builder - Builder for R function formal parameters and call arguments.
- RngSeed
Contract 🔒 - The seed contract of
stats::simulate(), which#[miniextendr(rng(seed = <param>))]writes into a standalone wrapper in the orderstats:::simulate.lmuses (#2198). - Roxygen
Builder - Builder for generating roxygen2 documentation tags.
Enums§
- Call
Attribution - Which frame a generated wrapper hands to
.Call(.., .call = ..)and uses as the raise fallback (.miniextendr_raise_condition(.val, <default>)).
Constants§
- FRAMEWORK_
FORMALS 🔒 - The R names a declared formal must not take, beyond R’s own syntax rules:
the names the generated wrapper binds or reads in the function’s frame
(#1842). Another dotted name is the framework’s only when it starts with
one of
FRAMEWORK_FORMAL_PREFIXES. - FRAMEWORK_
FORMAL_ 🔒PREFIXES - Prefixes of the R names the framework generates (locals such as
.mx_calland.mx_self, the wrappers preamble’s.miniextendr_*helpers, the.rdata_*helpers#[derive(ExternalPtr)]writes for a sidecar, the write-time.__MX_*placeholders): a declared formal starting with one is refused.
Functions§
- build_
r_ 🔒call_ args_ from_ sig - Build R
.Call()arguments from a Rust function signature. - build_
r_ 🔒formals_ from_ sig - Build R formal parameters from a Rust function signature, with optional defaults.
- check_
r_ 🔒formals - Check the R formals a signature produces, before any wrapper is generated.
- declared_
formal_ 🔒problem - Why
formalcan’t be a declared formal, orNonewhen it can: it must be a syntactic R name (crate::naming::is_syntactic_r_name: letters, digits,.and_, not starting with a digit,_or.and a digit, and not a reserved word), not...or..1(R’s dots), and none of the names the generated wrapper binds itself (FRAMEWORK_FORMALS,FRAMEWORK_FORMAL_PREFIXES). - is_
missing_ 🔒type - Check if a type is
Missing<T>by examining the last path segment. - normalize_
r_ arg_ string - Normalizes a Rust argument name (its
crate::naming::ident_name, nor#) for R. - r_
formal_ 🔒names - The R formal each parameter of a signature becomes, with the parameter’s
ident:
Formals::ofits name. The&Dots/LazyDotsparameter becomes...wherever it sits and is skipped, as are receivers, non-ident patterns and anNArgsparameter, which is no formal (#1860). - split_
choice_ 🔒list - Split a comma-separated choices list (as given to
choices(param = "a, b, c")) into individual trimmed entries. Surrounding double-quotes are tolerated so users can spell the list either way:"a, b"or"\"a\", \"b\"". - with_
call_ 🔒formal - Append a standalone wrapper’s
CallAttribution::formalto its joinedformals(#1613). The formal goes last: after...and after any formal that follows the dots, so positional extras land in the dots and.callis matched by name only; a wrapper without other formals takes it alone.