#[repr(transparent)]pub struct SEXP(pub *mut SEXPREC);Expand description
R’s pointer type for S-expressions.
This is a newtype wrapper around *mut SEXPREC that implements Send and Sync.
SEXP is just a handle (pointer) - the actual data it points to is managed by R’s
garbage collector and should only be accessed on R’s main thread.
§Safety
While SEXP is Send+Sync (allowing it to be passed between threads), the data it points to must only be accessed on R’s main thread. The miniextendr runtime enforces this through the worker thread pattern.
§Equality Semantics
IMPORTANT: The derived PartialEq compares pointer equality, not semantic equality.
For proper R semantics (comparing object contents), use R_compute_identical.
// Pointer equality (fast, often wrong for R semantics)
if sexp1 == sexp2 { ... } // Only true if same pointer
// Semantic equality (correct R semantics)
if R_compute_identical(sexp1, sexp2, 16) != 0 { ... }Hash trait removed: SEXP no longer implements Hash because proper hashing
would require deep content inspection via R_compute_identical, which is too
expensive for general use. If you need SEXP as a HashMap key, use pointer identity:
// Store by pointer identity (common pattern for R symbol lookups)
let mut map: HashMap<*mut SEXPREC, Value> = HashMap::new();
map.insert(sexp.as_ptr(), value);Tuple Fields§
§0: *mut SEXPRECImplementations§
Source§impl SEXP
impl SEXP
Sourcepub const fn null() -> Self
pub const fn null() -> Self
Create a C null pointer SEXP (0x0).
This is not R’s NULL value (R_NilValue). R’s NULL is a real
heap-allocated singleton; a C null pointer is just address zero. Passing
SEXP::null() where R expects R_NilValue will corrupt R’s GC state
and likely segfault.
Use SEXP::nil() for R’s NULL. Only use null() for low-level
pointer initialization, ALTREP Sum/Min/Max “can’t compute” returns
(R checks != NULL, not != R_NilValue), or comparison against
uninitialized pointers.
See also: SEXP::nil(), SEXP::is_null(), SexpExt::is_nil()
Sourcepub fn nil() -> Self
pub fn nil() -> Self
Return R’s NULL singleton (R_NilValue).
This is not a C null pointer — it points to R’s actual nil object
on the heap. Use this for .Call() return values, SEXP arguments to
R API functions, and any slot in R data structures.
See also: SEXP::null(), SexpExt::is_nil(), SEXP::is_null()
Sourcepub const fn is_null(self) -> bool
pub const fn is_null(self) -> bool
Check if this SEXP is a C null pointer (0x0).
To check if an SEXP is R’s NULL (R_NilValue), use
SexpExt::is_nil() instead.
See also: SexpExt::is_nil(), SexpExt::is_null_or_nil()
Sourcepub fn blank_string() -> SEXP
pub fn blank_string() -> SEXP
R’s empty string "" singleton.
Sourcepub fn install_char(charsxp: SEXP) -> SEXP
pub fn install_char(charsxp: SEXP) -> SEXP
Create an R symbol (SYMSXP) from a CHARSXP.
Equivalent to Rf_installChar(charsxp). The symbol is interned
in R’s global symbol table and never garbage collected.
Sourcepub fn symbol(name: &str) -> SEXP
pub fn symbol(name: &str) -> SEXP
Create an R symbol (SYMSXP) from a Rust &str.
Combines SEXP::charsxp() + Rf_installChar into one call.
The symbol is interned and never garbage collected.
Sourcepub fn scalar_integer(x: i32) -> SEXP
pub fn scalar_integer(x: i32) -> SEXP
Create a length-1 integer vector.
Sourcepub fn scalar_real(x: f64) -> SEXP
pub fn scalar_real(x: f64) -> SEXP
Create a length-1 real vector.
Sourcepub fn scalar_logical(x: bool) -> SEXP
pub fn scalar_logical(x: bool) -> SEXP
Create a length-1 logical vector.
Sourcepub fn scalar_logical_raw(x: i32) -> SEXP
pub fn scalar_logical_raw(x: i32) -> SEXP
Create a length-1 logical vector from raw i32 (0=FALSE, 1=TRUE, NA_LOGICAL=NA).
Accepts 0 (FALSE), 1 (TRUE), or NA_LOGICAL (i32::MIN) for NA.
Prefer scalar_logical for non-NA values.
Sourcepub fn scalar_raw(x: u8) -> SEXP
pub fn scalar_raw(x: u8) -> SEXP
Create a length-1 raw vector.
Sourcepub fn scalar_complex(x: Rcomplex) -> SEXP
pub fn scalar_complex(x: Rcomplex) -> SEXP
Create a length-1 complex vector.
Sourcepub fn scalar_string(charsxp: SEXP) -> SEXP
pub fn scalar_string(charsxp: SEXP) -> SEXP
Create a length-1 character vector from a CHARSXP.
Sourcepub fn scalar_string_from_str(s: &str) -> SEXP
pub fn scalar_string_from_str(s: &str) -> SEXP
Create a length-1 character vector from a Rust &str.
Sourcepub fn names_symbol() -> SEXP
pub fn names_symbol() -> SEXP
R’s names attribute symbol.
Sourcepub fn dim_symbol() -> SEXP
pub fn dim_symbol() -> SEXP
R’s dim attribute symbol.
Sourcepub fn dimnames_symbol() -> SEXP
pub fn dimnames_symbol() -> SEXP
R’s dimnames attribute symbol.
Sourcepub fn class_symbol() -> SEXP
pub fn class_symbol() -> SEXP
R’s class attribute symbol.
Sourcepub fn levels_symbol() -> SEXP
pub fn levels_symbol() -> SEXP
R’s levels attribute symbol (factors).
Sourcepub fn tsp_symbol() -> SEXP
pub fn tsp_symbol() -> SEXP
R’s tsp attribute symbol (time series).
Sourcepub fn base_namespace() -> SEXP
pub fn base_namespace() -> SEXP
R’s base namespace environment.
Sourcepub fn missing_arg() -> SEXP
pub fn missing_arg() -> SEXP
R’s missing argument sentinel.
Trait Implementations§
Source§impl AltrepSexpExt for SEXP
impl AltrepSexpExt for SEXP
Source§unsafe fn altrep_data1<T: TypedExternal>(&self) -> Option<ExternalPtr<T>>
unsafe fn altrep_data1<T: TypedExternal>(&self) -> Option<ExternalPtr<T>>
ExternalPtr<T>. Read moreSource§unsafe fn altrep_data1_mut_ref<T: TypedExternal>(
&self,
) -> Option<&'static mut T>
unsafe fn altrep_data1_mut_ref<T: TypedExternal>( &self, ) -> Option<&'static mut T>
Source§unsafe fn altrep_data2(&self) -> SEXP
unsafe fn altrep_data2(&self) -> SEXP
Source§unsafe fn set_altrep_data2(&self, data2: SEXP)
unsafe fn set_altrep_data2(&self, data2: SEXP)
Source§impl IntoR for SEXP
impl IntoR for SEXP
Source§type Error = Infallible
type Error = Infallible
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Source§impl PairListExt for SEXP
impl PairListExt for SEXP
Source§fn lcons(self, cdr: SEXP) -> SEXP
fn lcons(self, cdr: SEXP) -> SEXP
cdr as CDR.Source§unsafe fn cons_unchecked(self, cdr: SEXP) -> SEXP
unsafe fn cons_unchecked(self, cdr: SEXP) -> SEXP
Source§unsafe fn car_unchecked(&self) -> SEXP
unsafe fn car_unchecked(&self) -> SEXP
Source§unsafe fn cdr_unchecked(&self) -> SEXP
unsafe fn cdr_unchecked(&self) -> SEXP
Source§unsafe fn set_tag_unchecked(&self, tag: SEXP)
unsafe fn set_tag_unchecked(&self, tag: SEXP)
Source§impl SexpExt for SEXP
impl SexpExt for SEXP
Source§fn is_null_or_nil(&self) -> bool
fn is_null_or_nil(&self) -> bool
Source§unsafe fn len_unchecked(&self) -> usize
unsafe fn len_unchecked(&self) -> usize
Source§unsafe fn as_slice<T: RNativeType>(&self) -> &'static [T]
unsafe fn as_slice<T: RNativeType>(&self) -> &'static [T]
Source§unsafe fn as_mut_slice<T: RNativeType>(&self) -> &'static mut [T]
unsafe fn as_mut_slice<T: RNativeType>(&self) -> &'static mut [T]
Source§unsafe fn as_slice_unchecked<T: RNativeType>(&self) -> &'static [T]
unsafe fn as_slice_unchecked<T: RNativeType>(&self) -> &'static [T]
Source§fn is_integer(&self) -> bool
fn is_integer(&self) -> bool
Source§fn is_logical(&self) -> bool
fn is_logical(&self) -> bool
Source§fn is_character(&self) -> bool
fn is_character(&self) -> bool
Source§fn is_complex(&self) -> bool
fn is_complex(&self) -> bool
Source§fn is_external_ptr(&self) -> bool
fn is_external_ptr(&self) -> bool
Source§fn is_environment(&self) -> bool
fn is_environment(&self) -> bool
Source§fn is_language(&self) -> bool
fn is_language(&self) -> bool
Source§fn is_pair_list(&self) -> bool
fn is_pair_list(&self) -> bool
Source§fn is_function(&self) -> bool
fn is_function(&self) -> bool
Source§fn is_data_frame(&self) -> bool
fn is_data_frame(&self) -> bool
Source§fn is_numeric(&self) -> bool
fn is_numeric(&self) -> bool
Source§fn is_number(&self) -> bool
fn is_number(&self) -> bool
Source§fn is_vector_atomic(&self) -> bool
fn is_vector_atomic(&self) -> bool
Source§fn is_vector_list(&self) -> bool
fn is_vector_list(&self) -> bool
Source§fn coerce(&self, target: SEXPTYPE) -> SEXP
fn coerce(&self, target: SEXPTYPE) -> SEXP
Source§fn get_dimnames(&self) -> SEXP
fn get_dimnames(&self) -> SEXP
dimnames attribute.Source§fn set_dimnames(&self, dimnames: SEXP)
fn set_dimnames(&self, dimnames: SEXP)
dimnames attribute.Source§fn get_levels(&self) -> SEXP
fn get_levels(&self) -> SEXP
levels attribute (factors).Source§fn set_levels(&self, levels: SEXP)
fn set_levels(&self, levels: SEXP)
levels attribute (factors).Source§fn get_row_names(&self) -> SEXP
fn get_row_names(&self) -> SEXP
row.names attribute.Source§fn set_row_names(&self, row_names: SEXP)
fn set_row_names(&self, row_names: SEXP)
row.names attribute.Source§fn inherits_class(&self, class: &CStr) -> bool
fn inherits_class(&self, class: &CStr) -> bool
Source§fn string_elt_str(&self, i: isize) -> Option<&str>
fn string_elt_str(&self, i: isize) -> Option<&str>
Option<&str>. Read moreSource§fn set_string_elt(&self, i: isize, charsxp: SEXP)
fn set_string_elt(&self, i: isize, charsxp: SEXP)
Source§fn is_na_string(&self) -> bool
fn is_na_string(&self) -> bool
NA_character_.Source§fn vector_elt(&self, i: isize) -> SEXP
fn vector_elt(&self, i: isize) -> SEXP
Source§fn integer_elt(&self, i: isize) -> i32
fn integer_elt(&self, i: isize) -> i32
Source§fn logical_elt(&self, i: isize) -> i32
fn logical_elt(&self, i: isize) -> i32
Source§fn complex_elt(&self, i: isize) -> Rcomplex
fn complex_elt(&self, i: isize) -> Rcomplex
Source§fn set_integer_elt(&self, i: isize, v: i32)
fn set_integer_elt(&self, i: isize, v: i32)
Source§fn set_real_elt(&self, i: isize, v: f64)
fn set_real_elt(&self, i: isize, v: f64)
Source§fn set_logical_elt(&self, i: isize, v: i32)
fn set_logical_elt(&self, i: isize, v: i32)
Source§fn set_complex_elt(&self, i: isize, v: Rcomplex)
fn set_complex_elt(&self, i: isize, v: Rcomplex)
Source§fn set_raw_elt(&self, i: isize, v: u8)
fn set_raw_elt(&self, i: isize, v: u8)
Source§fn r_char_str(&self) -> Option<&str>
fn r_char_str(&self) -> Option<&str>
&str from a CHARSXP. Returns None for NA_character_.Source§fn resize(&self, newlen: R_xlen_t) -> SEXP
fn resize(&self, newlen: R_xlen_t) -> SEXP
Source§fn shallow_duplicate(&self) -> SEXP
fn shallow_duplicate(&self) -> SEXP
Rf_shallow_duplicate(x).Source§unsafe fn string_elt_unchecked(&self, i: isize) -> SEXP
unsafe fn string_elt_unchecked(&self, i: isize) -> SEXP
Source§unsafe fn set_string_elt_unchecked(&self, i: isize, charsxp: SEXP)
unsafe fn set_string_elt_unchecked(&self, i: isize, charsxp: SEXP)
Source§unsafe fn vector_elt_unchecked(&self, i: isize) -> SEXP
unsafe fn vector_elt_unchecked(&self, i: isize) -> SEXP
Source§unsafe fn set_vector_elt_unchecked(&self, i: isize, val: SEXP)
unsafe fn set_vector_elt_unchecked(&self, i: isize, val: SEXP)
Source§unsafe fn get_attr_unchecked(&self, name: SEXP) -> SEXP
unsafe fn get_attr_unchecked(&self, name: SEXP) -> SEXP
Source§unsafe fn set_attr_unchecked(&self, name: SEXP, val: SEXP)
unsafe fn set_attr_unchecked(&self, name: SEXP, val: SEXP)
Source§impl TryFromSexp for SEXP
Pass-through conversion for raw SEXP values with ALTREP auto-materialization.
impl TryFromSexp for SEXP
Pass-through conversion for raw SEXP values with ALTREP auto-materialization.
This allows SEXP to be used directly in #[miniextendr] function signatures.
When R passes an ALTREP vector (e.g., 1:10, seq_len(N)),
ensure_materialized is called
automatically to force materialization on the R main thread. After this,
the SEXP’s data pointer is stable and safe to access from any thread.
§ALTREP handling
| Input | Result |
|---|---|
| Regular SEXP | Passed through unchanged |
| ALTREP SEXP | Materialized via ensure_materialized, then passed through |
To receive ALTREP without materializing, use
AltrepSexp as the parameter type instead.
To receive the raw SEXP without any conversion (including no materialization),
use extern "C-unwind".
See docs/ALTREP_SEXP.md for the full guide.
§Safety
SEXP handles are only valid on R’s main thread. Use with
#[miniextendr(unsafe(main_thread))] functions.
Source§fn try_from_sexp(sexp: SEXP) -> Result<Self, Self::Error>
fn try_from_sexp(sexp: SEXP) -> Result<Self, Self::Error>
Converts a SEXP, auto-materializing ALTREP vectors.
If the input is ALTREP, ensure_materialized
is called to force materialization on the R main thread. After
materialization the data pointer is stable and the SEXP can be safely
sent to other threads.