Skip to main content

warning

Macro warning 

Source
macro_rules! warning {
    (class = $class:expr, $($arg:tt)*) => { ... };
    ($($arg:tt)*) => { ... };
}
Expand description

Raise an R warning from Rust with rust_warning class layering.

Requires error_in_r mode (the default for #[miniextendr] functions). 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.

§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