Expand description
Conversions from R SEXP to Rust types.
This module provides TryFromSexp implementations for converting R values to Rust types:
| R Type | Rust Type | Access Method |
|---|---|---|
| INTSXP | i32, &[i32] | INTEGER() / DATAPTR_RO |
| REALSXP | f64, &[f64] | REAL() / DATAPTR_RO |
| LGLSXP | RLogical, &[RLogical] | LOGICAL() / DATAPTR_RO |
| RAWSXP | u8, &[u8] | RAW() / DATAPTR_RO |
| CPLXSXP | Rcomplex | COMPLEX() / DATAPTR_RO |
| STRSXP | &str, String | ) + R_CHAR() / Rf_translateCharUTF8() |
§Submodules
| Module | Contents |
|---|---|
logical | Rboolean.string_elt(bool, Option<bool> |
coerced_scalars | Multi-source numeric scalars (i8..usize) + large integers (i64, u64) |
references | Borrowed views: &T, &mut T, &[T], Vec<&T> |
strings | &str, String, char from STRSXP |
na_vectors | Vec<Option<T>>, Box<[Option<T>]> with NA awareness |
collections | HashMap, BTreeMap, HashSet, BTreeSet |
cow_and_paths | Cow<[T]>, PathBuf, OsString, string sets |
§Thread Safety
The trait provides two methods:
TryFromSexp::try_from_sexp- checked version with debug thread assertionsTryFromSexp::try_from_sexp_unchecked- unchecked version for performance-critical paths
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§
- Sexp
Length Error - Error describing an unexpected R object length.
- Sexp
NaError - Error for NA values in conversions that require non-missing values.
- Sexp
Type Error - Error describing an unexpected R
SEXPTYPE.
Enums§
- Sexp
Error - Unified conversion error when decoding an R
SEXP.
Traits§
- TryFrom
Sexp - TryFrom-style trait for converting SEXP to Rust types.
Functions§
- charsxp_
to_ 🔒 ⚠cow charsxp_to_cowis now just an alias — all CHARSXPs are UTF-8 (asserted at init), so there’s no non-UTF-8 fallback path. ReturnsCow::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 onR_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_sliceforfrom_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.