Skip to main content

charsxp_to_string_lossy

Function charsxp_to_string_lossy 

Source
pub(crate) unsafe fn charsxp_to_string_lossy(charsxp: SEXP) -> Option<String>
Expand description

Convert CHARSXP to an owned, lossy String.

NA/null-defensive: returns None for NA_character_, R_NilValue, or a null SEXP. Non-UTF-8 bytes are replaced (CStr::to_string_lossy) rather than rejected. Unlike charsxp_to_str (the UTF-8-asserted hot path for package-internal CHARSXPs), this is for defensive reads of arbitrary R objects — S4 class attributes, geterrmessage() output, vctrs field names, tzone attributes — where the CHARSXP’s origin and encoding aren’t guaranteed.

§Safety

charsxp must be a valid SEXP. It may be R_NilValue or a null SEXP (both map to None); if it is neither of those and not NA_character_, it must actually be a CHARSXP.