macro_rules! warning {
($($t: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");A leading call = none raises the warning without a call, like R’s
warning(..., call. = FALSE): conditionCall(w) is NULL and the
printed warning has no In f(...) : prefix. Use it for a warning about the
data rather than about the call (see
conditions without a call):
warning!(call = none, class = "pkg_override", data = { row = row }, "row {row} overrides an earlier row");§See also
crate::error!— fatal sibling; aborts the call instead of continuing.crate::defer_warning!/crate::defer_warning()— queue the warning and still return the value (signalled when the call returns).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