Skip to main content

Module na_vectors

Module na_vectors 

Source
Expand description

NA-aware vector conversions (Vec<Option<T>>, Box<[Option<T>]>).

The SEXPTYPE literals here are the source of truth (#882). The macro that generates the native-type impls is passed the tag as $sexptype from the caller (where the concrete element type is known); the hand-written logical impls use LGLSXP because bool/Rboolean are not RNativeType (R logicals are i32), and the string/raw impls use STRSXP/RAWSXP literals because those element types have no RNativeType collapse — leave them.

Maps R’s NA values to None and non-NA values to Some(v). Covers native types (i32, f64, u8), logical (bool, Rboolean, RLogical), string (Option<String>), complex (Option<Rcomplex>), and coerced numeric types (Option<i64>, Option<u64>, etc.).

§Tradeoff

Use the NA-rejecting sibling impls (Vec<T>, Box<[T]>) when R guarantees no NA — they’re cheaper (no per-element Option discriminant) and reject NA at conversion time. Failure mode of binding plain Vec<i32> when the R caller can pass NA_integer_: a single NA element silently round-trips as i32::MIN, the R NA sentinel, which is a footgun for arithmetic downstream.

Outbound counterpart: Vec<Option<T>> impls in crate::into_r.

Re-exports§

use crate::coerce::TryCoerce; 🔒
use crate::from_r::SexpError; 🔒
use crate::from_r::SexpNaError; 🔒
use crate::from_r::SexpTypeError; 🔒
use crate::from_r::TryFromSexp; 🔒
use crate::from_r::coerce_value; 🔒
use crate::from_r::from_numeric_vec_with; 🔒
use crate::from_r::map_strsxp_with; 🔒
use crate::from_r::r_slice; 🔒
use crate::from_r::try_charsxp_to_str; 🔒
use crate::IsNA; 🔒
use crate::IsNA; 🔒
use crate::RLogical; 🔒
use crate::Rboolean; 🔒
use crate::SEXP; 🔒
use crate::SEXPTYPE; 🔒
use crate::SexpExt; 🔒

Macros§

impl_vec_option_try_from_sexp 🔒
Macro for NA-aware R vector → Vec<Option<T>> conversions.
impl_vec_option_try_from_sexp_numeric 🔒

Functions§

try_from_sexp_numeric_option_vec 🔒