Skip to main content

build_factor_with_levels

Function build_factor_with_levels 

Source
pub fn build_factor_with_levels(indices: &[i32], level_names: &[&str]) -> SEXP
Expand description

Build a factor SEXP from indices and level names in a single call.

Keeps the levels STRSXP rooted from allocation through build_factor, so callers don’t need to manage the levels protection themselves. The returned factor SEXP is not protected — caller must protect or return it.

This is the recommended path for one-shot factor construction; for repeated calls with the same levels prefer caching via build_levels_sexp_cached (no protection needed because the cached SEXP is on R’s precious list).

The levels container roots its strings; the container and the factor payload are rooted while being built.