Skip to main content

scatter_native

Function scatter_native 

Source
unsafe fn scatter_native<T: RNativeType + Copy>(
    src: SEXP,
    present_idx: &[usize],
    n_rows: usize,
) -> SEXP
Expand description

Scatter a dense typed column into a fresh SEXP of length n_rows, placing the j-th source value at row present_idx[j] and the per-type NA sentinel (RNativeType::R_NA) at every absent row.

The sparse-placing inverse of gather_native. Generic over the R element type: f64/i32/RLogical/u8/Rcomplex each resolve to the correct storage via their RNativeType impl, so the whole copy is a flat slice write with no per-element FFI call. Raw (u8) has no R NA, so absent positions become 0x00.

ยงSafety

R main thread; src must be a T::SEXP_TYPE vector with at least present_idx.len() elements, and every index in present_idx must be < n_rows. The returned SEXP is unprotected (see scatter_column). No allocation occurs between allocating out and filling it, so out cannot be reaped mid-scatter.