Expand description
Error handling helpers for R API calls.
§Default path: error_in_r (the standard for #[miniextendr])
Every #[miniextendr] function runs inside
with_r_unwind_protect_error_in_r.
Rust panics and user-raised conditions (error!(), warning!(), message!(),
condition!()) are caught, packaged as a tagged SEXP, and returned normally.
The generated R wrapper inspects the SEXP and raises the appropriate R condition
with rust_* class layering. No Rf_error longjmp happens on this path.
User code should use:
panic!()— for unrecoverable Rust errors (becomesrust_errorin R)error!()/warning!()/message!()/condition!()— for structured R conditions (seecrate::condition)
§When Rf_error fires
Rf_error / Rf_errorcall (longjmp) is only used on three paths where there
is no R wrapper to inspect a tagged SEXP:
- Trait-ABI vtable shims — cross-package C-ABI calls go through
with_r_unwind_protect(non-error_in_r). - ALTREP
RUnwindguard — ALTREP callbacks invoked from R’s GC / vector dispatch usewith_r_unwind_protect_sourced. - Explicit opt-out —
#[miniextendr(no_error_in_r)]/unwrap_in_r.
r_stop (this module) is the internal Rust wrapper around Rf_error. It is
used by proc-macro generated argument validation and return-type unwrapping,
which run before the closure enters with_r_unwind_protect. User code
should never call r_stop directly.
§Example
use miniextendr_api::miniextendr;
#[miniextendr]
fn validate_input(x: i32) -> i32 {
assert!(x >= 0, "x must be non-negative, got {x}");
x * 2
}Functions§
- _r_
print_ 👻newline - Print a newline to R’s console (internal implementation). Automatically routes to R’s main thread if called from a worker thread.
- _r_
print_ 👻str - Print a message to R’s console (internal implementation). Automatically routes to R’s main thread if called from a worker thread.
- r_stop
- Raise an R error via
Rf_error(longjmp). Do not call from user code. - r_
warning - Raise an R warning with the given message.