Skip to main content

gather_native

Function gather_native 

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

Gather the rows at idx (0-based, in order) from a contiguous primitive column into a fresh dense vector, where out[j] = src[idx[j]].

Generic over the R element type: f64/i32/RLogical/u8/Rcomplex each resolve to the correct REAL/INTEGER/LOGICAL/RAW/COMPLEX storage via their RNativeType impl, so the copy is a plain slice gather with no per-element FFI call.

ยงSafety

R main thread; src must be a T::SEXP_TYPE vector and every index in idx must be < xlength(src). The returned SEXP is unprotected (see gather_column). No allocation occurs between allocating out and filling it, so out cannot be reaped mid-gather.