Expand description
miniextendr-engine: standalone R embedding for Rust binaries and tests.
This crate centralizes libR linking (via build.rs), R initialization, and
a minimal runtime handle for processing events and interrupts. It is intended
for Rust-only executables and integration tests that embed R.
Not for R packages: this crate uses non-API R internals
(Rembedded.h, Rinterface.h). For R packages, depend on miniextendr-api
and keep nonapi disabled.
§When to use
- Rust binaries that embed R.
- Integration tests or benchmarks that need full control over R startup.
§Quick start
ⓘ
// SAFETY: Must be called once, from the main thread.
let engine = unsafe {
miniextendr_engine::REngine::build()
.with_args(&["R", "--quiet", "--vanilla"])
.init()
.expect("Failed to initialize R")
};
// ... use R APIs from the main thread ...
std::mem::forget(engine); // optional: intentionally leak the handle§Initialization details
- Ensures
R_HOME(viaR RHOME) if missing. - Calls
Rf_initialize_Rdirectly to avoid doublesetup_Rmainloop(). - Calls
setup_Rmainloop()exactly once after initialization.
§Runtime sentinel
ⓘ
if miniextendr_engine::r_initialized_sentinel() {
// R has been initialized in this process.
}§Safety
- Must only be initialized once per process.
- Must be called from the main thread.
- No shutdown:
Rf_endEmbeddedRis intentionally not called because the cleanup path is not reentrant-safe. The OS reclaims resources on exit.
Structs§
- REngine
- Handle to an initialized R runtime.
- REngine
Builder - Builder for configuring and initializing the R runtime.
Enums§
- REngine
Error - Errors that can occur during R engine initialization.
Statics§
- R_
CStack 🔒 ⚠Dir - R_
CStack 🔒 ⚠Start - R_
Interactive 🔒 ⚠ - R_
Signal 🔒 ⚠Handlers
Functions§
- R_
Check 🔒 ⚠User Interrupt - R_
Process 🔒 ⚠Events - Rf_
endEmbeddedR 🔒 ⚠ - Rf_
initialize_ 🔒 ⚠R - ensure_
r_ 🔒home_ env - r_
initialized_ sentinel - Check whether
Rf_initialize_Rhas run by inspecting stack sentinels. - set_
r_ 🔒 ⚠interactive - Write to R’s global
R_Interactiveflag. - set_
r_ 🔒 ⚠signal_ handlers - Write to R’s global
R_SignalHandlersflag. - setup_
Rmainloop 🔒 ⚠