Skip to main content

dollar_extract

Function dollar_extract 

Source
pub unsafe fn dollar_extract(
    target: SEXP,
    name: &str,
) -> Result<SEXP, REvalError>
Expand description

Build and evaluate target$name — the R $ extraction operator.

This is a convenience wrapper that avoids hand-rolling Rf_install("$") + Rf_lang3(...) + R_tryEval(...) ladders. Equivalent to:

ⓘ
RCall::new("$")
    .arg(target)
    .arg(SEXP::scalar_string_from_str(name))
    .eval_base()

with the name argument protected while the call is built.

§Safety

  • Must be called from the R main thread.
  • target must be a valid SEXP (typically a list, environment, or S4 object that supports $ extraction).

§Returns

  • Ok(SEXP) with the extracted value (unprotected — caller should protect if needed).
  • Err(REvalError) with R’s error if $ extraction fails.