macro_rules! warning {
(class = $class:expr, data = $data:tt, $($arg:tt)*) => { ... };
(data = $data:tt, $($arg:tt)*) => { ... };
(class = $class:expr, $($arg:tt)*) => { ... };
($($arg:tt)*) => { ... };
}Expand description
Raise an R warning from Rust with rust_warning class layering.
Rides the tagged-condition transport that every #[miniextendr] function uses.
Unlike panic!, execution continues after warning! is caught by a handler.
The raised condition has class c("rust_warning", "simpleWarning", "warning", "condition").
An optional class = "name" form prepends a custom class. An optional
data = ... form (after class, before the message) attaches named fields
readable as w$<name> in handlers — same grammar and supported value types
as crate::error! (see there for details):
ⓘ
warning!(class = "truncation", data = ("dropped", n), "dropped {n} rows");§See also
crate::error!— fatal sibling; aborts the call instead of continuing.crate::message!/crate::condition!— softer signal kinds (muffled bysuppressMessages/ silent without handler, respectively).std::panic!— escape hatch when “continue after this” is not a sensible semantic.crate::error_value— tagged-SEXP transport rationale.
No name-collision caveat: there is no pub mod warning, so
use miniextendr_api::warning; then warning!(...) works directly.
§Example
ⓘ
use miniextendr_api::warning;
#[miniextendr]
fn maybe_warn(x: i32) -> i32 {
if x > 100 {
warning!("x is large: {x}");
}
x * 2
}withCallingHandlers(
maybe_warn(200L),
warning = function(w) { cat("saw:", conditionMessage(w)); invokeRestart("muffleWarning") }
)
# saw: x is large: 200
# [1] 400