pub unsafe fn try_recover_r_sexp(
data_ptr: *const u8,
expected_type: SEXPTYPE,
expected_len: usize,
) -> Option<SEXP>Expand description
Try to recover the source R SEXP from a data pointer.
Given a pointer that may point into an R vector’s data area, this subtracts the known SEXPREC header size to get a candidate SEXP, then verifies it:
- The SEXP type tag (bits 0-4 of sxpinfo) matches
expected_type ALTREP(candidate)is false (only non-ALTREP vectors have fixed-offset data)XLENGTH(candidate)matchesexpected_len(safe for non-ALTREP)
Returns None if:
- The offset hasn’t been initialized yet
- The pointer doesn’t come from an R vector
- The candidate SEXP has the wrong type or length
- The candidate is an ALTREP vector (data not at fixed offset from SEXP)
§Safety
Must be called on R’s main thread. The data pointer must be valid
(i.e., it must point to readable memory for at least expected_len
elements, which is guaranteed if it came from an Arrow buffer).