pub fn with_r_thread<F, R>(f: F) -> RExpand description
Execute a closure on R’s main thread, returning the result.
This function can be called from any thread:
- From the main thread: executes the closure directly (re-entrant)
- From the worker thread (during
run_on_worker): sends the work to the main thread and blocks until completion
§Panics
- If
miniextendr_runtime_init()hasn’t been called yet - If called from a non-main thread without the
worker-threadfeature - If called from a non-main thread outside of a
run_on_workercontext (even with theworker-threadfeature)
§Example
ⓘ
use miniextendr_api::with_r_thread;
// From worker thread, safely call R APIs:
let sexp = with_r_thread(|| {
// This runs on R's main thread
SEXP::nil()
});