Skip to main content

Module from_r

Module from_r 

Source
Expand description

Conversions from R SEXP to Rust types.

This module provides TryFromSexp implementations for converting R values to Rust types:

R TypeRust TypeAccess Method
INTSXPi32, &[i32]INTEGER() / DATAPTR_RO
REALSXPf64, &[f64]REAL() / DATAPTR_RO
LGLSXPRLogical, &[RLogical]LOGICAL() / DATAPTR_RO
RAWSXPu8, &[u8]RAW() / DATAPTR_RO
CPLXSXPRcomplexCOMPLEX() / DATAPTR_RO
STRSXP&str, String) + R_CHAR() / Rf_translateCharUTF8()

§Submodules

ModuleContents
logicalRboolean.string_elt(bool, Option<bool>
coerced_scalarsMulti-source numeric scalars (i8..usize) + large integers (i64, u64)
referencesBorrowed views: &T, &mut T, &[T], Vec<&T>
strings&str, String, char from STRSXP
na_vectorsVec<Option<T>>, Box<[Option<T>]> with NA awareness
collectionsHashMap, BTreeMap, HashSet, BTreeSet
cow_and_pathsCow<[T]>, PathBuf, OsString, string sets

§Thread Safety

The trait provides two methods:

Use try_from_sexp_unchecked when you’re certain you’re on the main thread:

  • Inside ALTREP callbacks
  • Inside #[miniextendr(unsafe(main_thread))] functions
  • Inside extern "C-unwind" functions called directly by R

Modules§

coerced_scalars 🔒
Coerced scalar conversions (multi-source numeric) and large integer scalars.
collections 🔒
Collection conversions (HashMap, BTreeMap, HashSet, BTreeSet).
cow_and_paths 🔒
Cow, PathBuf, OsString, and string collection conversions.
logical 🔒
Logical type conversions (Rboolean, bool, Option variants).
na_vectors 🔒
NA-aware vector conversions (Vec<Option<T>>, Box<[Option<T>]>).
references 🔒
Reference conversions (borrowed views into R vectors).
strings 🔒
String conversions — STRSXP requires special handling via STRING_ELT.

Macros§

impl_option_map_try_from_sexp 🔒
impl_option_set_try_from_sexp 🔒
impl_set_try_from_sexp_bool 🔒
impl_set_try_from_sexp_numeric 🔒
impl_try_from_sexp_scalar_native 🔒
impl_vec_try_from_sexp_numeric 🔒
Implement TryFromSexp for Vec<$target> by coercing from integer/real/logical/raw.

Structs§

SexpLengthError
Error describing an unexpected R object length.
SexpNaError
Error for NA values in conversions that require non-missing values.
SexpTypeError
Error describing an unexpected R SEXPTYPE.

Enums§

SexpError
Unified conversion error when decoding an R SEXP.

Traits§

TryFromSexp
TryFrom-style trait for converting SEXP to Rust types.

Functions§

charsxp_to_cow 🔒
charsxp_to_cow is now just an alias — all CHARSXPs are UTF-8 (asserted at init), so there’s no non-UTF-8 fallback path. Returns Cow::Borrowed.
charsxp_to_str 🔒
Convert CHARSXP to &str — zero-copy from R’s string data.
charsxp_to_str_impl 🔒
Shared implementation: given a data pointer and CHARSXP, produce &str.
charsxp_to_str_unchecked 🔒
Unchecked version of charsxp_to_str (skips R thread checks on R_CHAR).
coerce_slice_to_vec 🔒
Helper to coerce a slice element-wise into a Vec.
is_na_real 🔒
Check if an f64 value is R’s NA_real_ (a specific NaN bit pattern).
r_slice 🔒
Create a slice from an R data pointer, handling the zero-length case.
r_slice_mut 🔒
Mutable version of r_slice for from_raw_parts_mut.
try_from_sexp_numeric_set 🔒
Convert numeric/logical/raw vectors to a set type with element-wise coercion.
try_from_sexp_numeric_vec 🔒
Convert numeric/logical/raw vectors to Vec<T> with element-wise coercion.