Skip to main content

with_r_thread_or_inline

Function with_r_thread_or_inline 

Source
fn with_r_thread_or_inline<R: Send + 'static, F: FnOnce() -> R + Send + 'static>(
    f: F,
) -> R
Expand description

Routes a closure to the R main thread if not already there.

  • If on main thread: executes directly
  • If in worker context: routes via with_r_thread
  • Otherwise: panics (R API calls from arbitrary threads are unsafe)

ยงPanics

Panics if called from a non-main thread without worker context. This prevents unsafe R API calls from arbitrary threads (e.g., Rayon).