pub struct Robj {
inner: SEXP,
}
Expand description
Wrapper for an R S-expression pointer (SEXP).
Create R objects from rust types and iterators:
use extendr_api::prelude::*;
test! {
// Different ways of making integer scalar 1.
let non_na : Option<i32> = Some(1);
let a : Robj = vec![1].into();
let b = r!(1);
let c = r!(vec![1]);
let d = r!(non_na);
let e = r!([1]);
assert_eq!(a, b);
assert_eq!(a, c);
assert_eq!(a, d);
assert_eq!(a, e);
// Different ways of making boolean scalar TRUE.
let a : Robj = true.into();
let b = r!(TRUE);
assert_eq!(a, b);
// Create a named list
let a = list!(a = 1, b = "x");
assert_eq!(a.len(), 2);
// Use an iterator (like 1:10)
let a = r!(1 ..= 10);
assert_eq!(a, r!([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
// Use an iterator (like (1:10)[(1:10) %% 3 == 0])
let a = (1 ..= 10).filter(|v| v % 3 == 0).collect_robj();
assert_eq!(a, r!([3, 6, 9]));
}
Convert to/from Rust vectors.
use extendr_api::prelude::*;
test! {
let a : Robj = r!(vec![1., 2., 3., 4.]);
let b : Vec<f64> = a.as_real_vector().unwrap();
assert_eq!(a.len(), 4);
assert_eq!(b, vec![1., 2., 3., 4.]);
}
Iterate over names and values.
use extendr_api::prelude::*;
test! {
let abc = list!(a = 1, b = "x", c = vec![1, 2]);
let names : Vec<_> = abc.names().unwrap().collect();
let names_and_values : Vec<_> = abc.as_list().unwrap().iter().collect();
assert_eq!(names, vec!["a", "b", "c"]);
assert_eq!(names_and_values, vec![("a", r!(1)), ("b", r!("x")), ("c", r!(vec![1, 2]))]);
}
NOTE: as much as possible we wish to make this object safe (ie. no segfaults).
If you avoid using unsafe functions it is more likely that you will avoid panics and segfaults. We will take great trouble to ensure that this is true.
Fields§
§inner: SEXP
Implementations§
Source§impl Robj
impl Robj
pub fn from_sexp(sexp: SEXP) -> Self
Sourcepub fn from_sexp_ref(sexp: &SEXP) -> &Self
pub fn from_sexp_ref(sexp: &SEXP) -> &Self
A ref of an robj can be constructed from a ref to a SEXP as they have the same layout.
Source§impl Robj
impl Robj
Sourcepub fn is_na(&self) -> bool
pub fn is_na(&self) -> bool
Is this object is an NA
scalar?
Works for character, integer and numeric types.
use extendr_api::prelude::*;
test! {
assert_eq!(r!(NA_INTEGER).is_na(), true);
assert_eq!(r!(NA_REAL).is_na(), true);
assert_eq!(r!(NA_STRING).is_na(), true);
}
Sourcepub fn as_integer_slice<'a>(&self) -> Option<&'a [i32]>
pub fn as_integer_slice<'a>(&self) -> Option<&'a [i32]>
Get a read-only reference to the content of an integer vector.
use extendr_api::prelude::*;
test! {
let robj = r!([1, 2, 3]);
assert_eq!(robj.as_integer_slice().unwrap(), [1, 2, 3]);
}
Sourcepub fn as_integer_vector(&self) -> Option<Vec<i32>>
pub fn as_integer_vector(&self) -> Option<Vec<i32>>
Get a Vec<i32>
copied from the object.
use extendr_api::prelude::*;
test! {
let robj = r!([1, 2, 3]);
assert_eq!(robj.as_integer_slice().unwrap(), vec![1, 2, 3]);
}
Sourcepub fn as_logical_slice(&self) -> Option<&[Rbool]>
pub fn as_logical_slice(&self) -> Option<&[Rbool]>
Get a read-only reference to the content of a logical vector using the tri-state Rbool. Returns None if not a logical vector.
use extendr_api::prelude::*;
test! {
let robj = r!([TRUE, FALSE]);
assert_eq!(robj.as_logical_slice().unwrap(), [TRUE, FALSE]);
}
Sourcepub fn as_logical_vector(&self) -> Option<Vec<Rbool>>
pub fn as_logical_vector(&self) -> Option<Vec<Rbool>>
Get a Vec<Rbool>
copied from the object
using the tri-state Rbool
.
Returns None
if not a logical vector.
use extendr_api::prelude::*;
test! {
let robj = r!([TRUE, FALSE]);
assert_eq!(robj.as_logical_vector().unwrap(), vec![TRUE, FALSE]);
}
Sourcepub fn as_logical_iter(&self) -> Option<impl Iterator<Item = &Rbool>>
pub fn as_logical_iter(&self) -> Option<impl Iterator<Item = &Rbool>>
Get an iterator over logical elements of this slice.
use extendr_api::prelude::*;
test! {
let robj = r!([TRUE, FALSE, NA_LOGICAL]);
let mut num_na = 0;
for val in robj.as_logical_iter().unwrap() {
if val.is_na() {
num_na += 1;
}
}
assert_eq!(num_na, 1);
}
Sourcepub fn as_real_slice(&self) -> Option<&[f64]>
pub fn as_real_slice(&self) -> Option<&[f64]>
Get a read-only reference to the content of a double vector. Note: the slice may contain NaN or NA values. We may introduce a “Real” type to handle this like the Rbool type.
use extendr_api::prelude::*;
test! {
let robj = r!([Some(1.), None, Some(3.)]);
let mut tot = 0.;
for val in robj.as_real_slice().unwrap() {
if !val.is_na() {
tot += val;
}
}
assert_eq!(tot, 4.);
}
Sourcepub fn as_real_iter(&self) -> Option<impl Iterator<Item = &f64>>
pub fn as_real_iter(&self) -> Option<impl Iterator<Item = &f64>>
Get an iterator over real elements of this slice.
use extendr_api::prelude::*;
test! {
let robj = r!([1., 2., 3.]);
let mut tot = 0.;
for val in robj.as_real_iter().unwrap() {
if !val.is_na() {
tot += val;
}
}
assert_eq!(tot, 6.);
}
Sourcepub fn as_real_vector(&self) -> Option<Vec<f64>>
pub fn as_real_vector(&self) -> Option<Vec<f64>>
Get a Vec<f64>
copied from the object.
use extendr_api::prelude::*;
test! {
let robj = r!([1., 2., 3.]);
assert_eq!(robj.as_real_vector().unwrap(), vec![1., 2., 3.]);
}
Sourcepub fn as_raw_slice(&self) -> Option<&[u8]>
pub fn as_raw_slice(&self) -> Option<&[u8]>
Get a read-only reference to the content of an integer or logical vector.
use extendr_api::prelude::*;
test! {
let robj = r!(Raw::from_bytes(&[1, 2, 3]));
assert_eq!(robj.as_raw_slice().unwrap(), &[1, 2, 3]);
}
Sourcepub fn as_integer_slice_mut(&mut self) -> Option<&mut [i32]>
pub fn as_integer_slice_mut(&mut self) -> Option<&mut [i32]>
Get a read-write reference to the content of an integer or logical vector.
Note that rust slices are 0-based so slice[1]
is the middle value.
use extendr_api::prelude::*;
test! {
let mut robj = r!([1, 2, 3]);
let slice : & mut [i32] = robj.as_integer_slice_mut().unwrap();
slice[1] = 100;
assert_eq!(robj, r!([1, 100, 3]));
}
Sourcepub fn as_real_slice_mut(&mut self) -> Option<&mut [f64]>
pub fn as_real_slice_mut(&mut self) -> Option<&mut [f64]>
Get a read-write reference to the content of a double vector.
Note that rust slices are 0-based so slice[1]
is the middle value.
use extendr_api::prelude::*;
test! {
let mut robj = r!([1.0, 2.0, 3.0]);
let slice = robj.as_real_slice_mut().unwrap();
slice[1] = 100.0;
assert_eq!(robj, r!([1.0, 100.0, 3.0]));
}
Sourcepub fn as_raw_slice_mut(&mut self) -> Option<&mut [u8]>
pub fn as_raw_slice_mut(&mut self) -> Option<&mut [u8]>
Get a read-write reference to the content of a raw vector.
use extendr_api::prelude::*;
test! {
let mut robj = r!(Raw::from_bytes(&[1, 2, 3]));
let slice = robj.as_raw_slice_mut().unwrap();
slice[1] = 100;
assert_eq!(robj, r!(Raw::from_bytes(&[1, 100, 3])));
}
Sourcepub fn as_string_vector(&self) -> Option<Vec<String>>
pub fn as_string_vector(&self) -> Option<Vec<String>>
Get a vector of owned strings. Owned strings have long lifetimes, but are much slower than references.
use extendr_api::prelude::*;
test! {
let robj1 = Robj::from("xyz");
assert_eq!(robj1.as_string_vector(), Some(vec!["xyz".to_string()]));
let robj2 = Robj::from(1);
assert_eq!(robj2.as_string_vector(), None);
}
Sourcepub fn as_str_vector(&self) -> Option<Vec<&str>>
pub fn as_str_vector(&self) -> Option<Vec<&str>>
Get a vector of string references. String references (&str) are faster, but have short lifetimes.
use extendr_api::prelude::*;
test! {
let robj1 = Robj::from("xyz");
assert_eq!(robj1.as_str_vector(), Some(vec!["xyz"]));
let robj2 = Robj::from(1);
assert_eq!(robj2.as_str_vector(), None);
}
Sourcepub fn as_str<'a>(&self) -> Option<&'a str>
pub fn as_str<'a>(&self) -> Option<&'a str>
Get a read-only reference to a scalar string type.
use extendr_api::prelude::*;
test! {
let robj1 = Robj::from("xyz");
let robj2 = Robj::from(1);
assert_eq!(robj1.as_str(), Some("xyz"));
assert_eq!(robj2.as_str(), None);
}
Sourcepub fn as_integer(&self) -> Option<i32>
pub fn as_integer(&self) -> Option<i32>
Get a scalar integer.
use extendr_api::prelude::*;
test! {
let robj1 = Robj::from("xyz");
let robj2 = Robj::from(1);
let robj3 = Robj::from(NA_INTEGER);
assert_eq!(robj1.as_integer(), None);
assert_eq!(robj2.as_integer(), Some(1));
assert_eq!(robj3.as_integer(), None);
}
Sourcepub fn as_real(&self) -> Option<f64>
pub fn as_real(&self) -> Option<f64>
Get a scalar real.
use extendr_api::prelude::*;
test! {
let robj1 = Robj::from(1);
let robj2 = Robj::from(1.);
let robj3 = Robj::from(NA_REAL);
assert_eq!(robj1.as_real(), None);
assert_eq!(robj2.as_real(), Some(1.));
assert_eq!(robj3.as_real(), None);
}
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Get a scalar rust boolean.
use extendr_api::prelude::*;
test! {
let robj1 = Robj::from(TRUE);
let robj2 = Robj::from(1.);
let robj3 = Robj::from(NA_LOGICAL);
assert_eq!(robj1.as_bool(), Some(true));
assert_eq!(robj2.as_bool(), None);
assert_eq!(robj3.as_bool(), None);
}
Sourcepub fn as_logical(&self) -> Option<Rbool>
pub fn as_logical(&self) -> Option<Rbool>
Get a scalar boolean as a tri-boolean Rbool value.
use extendr_api::prelude::*;
test! {
let robj1 = Robj::from(TRUE);
let robj2 = Robj::from([TRUE, FALSE]);
let robj3 = Robj::from(NA_LOGICAL);
assert_eq!(robj1.as_logical(), Some(TRUE));
assert_eq!(robj2.as_logical(), None);
assert_eq!(robj3.as_logical().unwrap().is_na(), true);
}
Trait Implementations§
Source§impl<Rhs> Add<Rhs> for Robj
impl<Rhs> Add<Rhs> for Robj
Source§fn add(self, rhs: Rhs) -> Self::Output
fn add(self, rhs: Rhs) -> Self::Output
Add two R objects, consuming the left hand side. panics on error.
use extendr_api::prelude::*;
test! {
// lhs and rhs get dropped here
let lhs = r!([1, 2]);
let rhs = r!([10, 20]);
assert_eq!(lhs + rhs, r!([11, 22]));
// lhs gets dropped and rhs is a temporary object.
let lhs = r!([1, 2]);
assert_eq!(lhs + 1000, r!([1001, 1002]));
// Only lhs gets dropped.
let lhs = r!([1, 2]);
let rhs = r!([10, 20]);
assert_eq!(lhs + &rhs, r!([11, 22]));
}
Source§impl<'a> AsTypedSlice<'a, Complex<f64>> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, Complex<f64>> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [c64]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [c64]>
Source§impl<'a> AsTypedSlice<'a, Rbool> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, Rbool> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [Rbool]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [Rbool]>
Source§impl<'a> AsTypedSlice<'a, Rcomplex> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, Rcomplex> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [Rcomplex]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [Rcomplex]>
Source§impl<'a> AsTypedSlice<'a, Rcplx> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, Rcplx> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [Rcplx]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [Rcplx]>
Source§impl<'a> AsTypedSlice<'a, Rfloat> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, Rfloat> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [Rfloat]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [Rfloat]>
Source§impl<'a> AsTypedSlice<'a, Rint> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, Rint> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [Rint]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [Rint]>
Source§impl<'a> AsTypedSlice<'a, Rstr> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, Rstr> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [Rstr]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [Rstr]>
Source§impl<'a> AsTypedSlice<'a, f64> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, f64> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [f64]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [f64]>
Source§impl<'a> AsTypedSlice<'a, i32> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, i32> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [i32]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [i32]>
Source§impl<'a> AsTypedSlice<'a, u8> for Robjwhere
Self: 'a,
impl<'a> AsTypedSlice<'a, u8> for Robjwhere
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [u8]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [u8]>
Source§impl Attributes for Robj
impl Attributes for Robj
Source§fn get_attrib<'a, N>(&self, name: N) -> Option<Robj>
fn get_attrib<'a, N>(&self, name: N) -> Option<Robj>
Robj
if it exists. Read moreSource§fn has_attrib<'a, N>(&self, name: N) -> bool
fn has_attrib<'a, N>(&self, name: N) -> bool
Source§fn set_attrib<N, V>(&mut self, name: N, value: V) -> Result<&mut Self>
fn set_attrib<N, V>(&mut self, name: N, value: V) -> Result<&mut Self>
Source§fn names(&self) -> Option<StrIter>
fn names(&self) -> Option<StrIter>
names
attribute as a string iterator if one exists. Read moreSource§fn set_names<T>(&mut self, names: T) -> Result<&mut Self>
fn set_names<T>(&mut self, names: T) -> Result<&mut Self>
names
attribute from a string iterator. Read moreSource§fn dim(&self) -> Option<Integers>
fn dim(&self) -> Option<Integers>
dim
attribute as an integer iterator if one exists. Read moreSource§fn dimnames(&self) -> Option<ListIter>
fn dimnames(&self) -> Option<ListIter>
dimnames
attribute as a list iterator if one exists. Read moreSource§fn class(&self) -> Option<StrIter>
fn class(&self) -> Option<StrIter>
class
attribute as a string iterator if one exists. Read moreSource§fn set_class<T>(&mut self, class: T) -> Result<&mut Self>
fn set_class<T>(&mut self, class: T) -> Result<&mut Self>
class
attribute from a string iterator, and return the same
object. Read moreSource§impl Conversions for Robj
impl Conversions for Robj
Source§fn as_language(&self) -> Option<Language>
fn as_language(&self) -> Option<Language>
Source§fn as_pairlist(&self) -> Option<Pairlist>
fn as_pairlist(&self) -> Option<Pairlist>
Source§fn as_expressions(&self) -> Option<Expressions>
fn as_expressions(&self) -> Option<Expressions>
Source§fn as_environment(&self) -> Option<Environment>
fn as_environment(&self) -> Option<Environment>
Source§fn as_function(&self) -> Option<Function>
fn as_function(&self) -> Option<Function>
Source§fn as_promise(&self) -> Option<Promise>
fn as_promise(&self) -> Option<Promise>
Source§impl<'de> Deserialize<'de> for Robj
impl<'de> Deserialize<'de> for Robj
Source§fn deserialize<D>(deserializer: D) -> Result<Robj, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Robj, D::Error>where
D: Deserializer<'de>,
Source§impl<'de> Deserializer<'de> for &'de Robj
impl<'de> Deserializer<'de> for &'de Robj
Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a unit value.Source§fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a bool
value.Source§fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting an i8
value.Source§fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting an i16
value.Source§fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting an i32
value.Source§fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting an i64
value.Source§fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a u8
value.Source§fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a u16
value.Source§fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a u32
value.Source§fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a u64
value.Source§fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a f32
value.Source§fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a f64
value.Source§fn deserialize_char<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a char
value.Source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_string<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moreSource§fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting an optional value. Read moreSource§fn deserialize_unit_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a unit struct with a
particular name.Source§fn deserialize_newtype_struct<V>(
self,
_name: &str,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
_name: &str,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a newtype struct with a
particular name.Source§fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a sequence of values and
knows how many values there are without looking at the serialized data.Source§fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a sequence of values.Source§fn deserialize_map<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a map of key-value pairs.Source§fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting a struct with a particular
name and fields.Source§fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Deserialize
type is expecting an enum value with a
particular name and possible variants.Source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize
implementations should expect to
deserialize their human-readable form. Read moreSource§impl<Rhs> Div<Rhs> for Robj
impl<Rhs> Div<Rhs> for Robj
Source§fn div(self, rhs: Rhs) -> Self::Output
fn div(self, rhs: Rhs) -> Self::Output
Divide two R objects, consuming the left hand side. panics on error.
use extendr_api::prelude::*;
test! {
// lhs and rhs get dropped here
let lhs = r!([10.0, 20.0]);
let rhs = r!([1.0, 2.0]);
assert_eq!(lhs / rhs, r!([10.0, 10.0]));
// lhs gets dropped and rhs is a temporary object.
let lhs = r!([10.0, 30.0]);
assert_eq!(lhs / 10.0, r!([1.0, 3.0]));
// Only lhs gets dropped.
let lhs = r!([10.0, 20.0]);
let rhs = r!([1.0, 2.0]);
assert_eq!(lhs / &rhs, r!([10.0, 10.0]));
}
Source§impl<'de> EnumAccess<'de> for &'de Robj
impl<'de> EnumAccess<'de> for &'de Robj
Source§type Error = Error
type Error = Error
Source§type Variant = &'de Robj
type Variant = &'de Robj
Visitor
that will be used to deserialize the content of the enum
variant.Source§fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant)>where
V: DeserializeSeed<'de>,
fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant)>where
V: DeserializeSeed<'de>,
variant
is called to identify which variant to deserialize. Read moreSource§impl Eval for Robj
impl Eval for Robj
Source§fn eval(&self) -> Result<Robj>
fn eval(&self) -> Result<Robj>
Source§fn eval_with_env(&self, env: &Environment) -> Result<Robj>
fn eval_with_env(&self, env: &Environment) -> Result<Robj>
Source§fn eval_blind(&self) -> Robj
fn eval_blind(&self) -> Robj
Source§impl<'a, T, const N: usize> From<&'a [T; N]> for Robjwhere
Self: 'a,
&'a T: ToVectorValue + 'a,
impl<'a, T, const N: usize> From<&'a [T; N]> for Robjwhere
Self: 'a,
&'a T: ToVectorValue + 'a,
Source§impl From<&Environment> for Robj
impl From<&Environment> for Robj
Source§fn from(val: &Environment) -> Self
fn from(val: &Environment) -> Self
Make an robj from a wrapper.
Source§impl From<&Expressions> for Robj
impl From<&Expressions> for Robj
Source§fn from(val: &Expressions) -> Self
fn from(val: &Expressions) -> Self
Make an robj from a wrapper.
Source§impl<'a, T, const N: usize> From<&'a mut [T; N]> for Robjwhere
Self: 'a,
&'a mut T: ToVectorValue + 'a,
impl<'a, T, const N: usize> From<&'a mut [T; N]> for Robjwhere
Self: 'a,
&'a mut T: ToVectorValue + 'a,
Source§impl From<Environment> for Robj
impl From<Environment> for Robj
Source§fn from(val: Environment) -> Self
fn from(val: Environment) -> Self
Make an robj from a wrapper.
Source§impl From<Expressions> for Robj
impl From<Expressions> for Robj
Source§fn from(val: Expressions) -> Self
fn from(val: Expressions) -> Self
Make an robj from a wrapper.
Source§impl<T> From<ExternalPtr<T>> for Robj
impl<T> From<ExternalPtr<T>> for Robj
Source§fn from(val: ExternalPtr<T>) -> Self
fn from(val: ExternalPtr<T>) -> Self
Source§impl<T> From<Option<ExternalPtr<T>>> for Robj
impl<T> From<Option<ExternalPtr<T>>> for Robj
Source§fn from(value: Option<ExternalPtr<T>>) -> Self
fn from(value: Option<ExternalPtr<T>>) -> Self
Source§impl From<PairlistIter> for Robj
impl From<PairlistIter> for Robj
Source§fn from(iter: PairlistIter) -> Self
fn from(iter: PairlistIter) -> Self
You can return a PairlistIter from a function.
Source§impl<T> From<RangeInclusive<T>> for Robjwhere
RangeInclusive<T>: RobjItertools,
<RangeInclusive<T> as Iterator>::Item: ToVectorValue,
T: ToVectorValue,
impl<T> From<RangeInclusive<T>> for Robjwhere
RangeInclusive<T>: RobjItertools,
<RangeInclusive<T> as Iterator>::Item: ToVectorValue,
T: ToVectorValue,
Source§fn from(val: RangeInclusive<T>) -> Self
fn from(val: RangeInclusive<T>) -> Self
Source§impl<T, E> From<Result<T, E>> for Robj
impl<T, E> From<Result<T, E>> for Robj
Panics if there is an error.
To use the ?
-operator, an extendr-function must return either extendr_api::error::Result
or std::result::Result
.
Use of panic!
in extendr is discouraged due to memory leakage.
Alternative behaviors enabled by feature toggles:
extendr-api supports different conversions from Result<T,E>
into Robj
.
Below, x_ok
represents an R variable on R side which was returned from rust via T::into_robj()
or similar.
Likewise, x_err
was returned to R side from rust via E::into_robj()
or similar.
extendr-api
result_list
:Ok(T)
is encoded aslist(ok = x_ok, err = NULL)
andErr
aslist(ok = NULL, err = e_err)
.result_condition'
:Ok(T)
is encoded asx_ok
andErr(E)
ascondition(msg="extendr_error", value = x_err, class=c("extendr_error", "error", "condition"))
- More than one enabled feature: Only one feature gate will take effect, the current order of precedence is [
result_list
,result_condition
, … ]. - Neither of the above (default):
Ok(T)
is encoded asx_ok
andErr(E)
will triggerthrow_r_error()
, which is discouraged.
use extendr_api::prelude::*;
fn my_func() -> Result<f64> {
Ok(1.0)
}
test! {
assert_eq!(r!(my_func()), r!(1.0));
}
Source§impl<T> From<T> for Robjwhere
T: ToVectorValue,
impl<T> From<T> for Robjwhere
T: ToVectorValue,
Source§impl Load for Robj
impl Load for Robj
Source§fn load<P: AsRef<Path>>(
path: &P,
format: PstreamFormat,
hook: Option<ReadHook>,
) -> Result<Robj>
fn load<P: AsRef<Path>>( path: &P, format: PstreamFormat, hook: Option<ReadHook>, ) -> Result<Robj>
version
should probably be 3.Source§fn from_reader<R: Read>(
reader: &mut R,
format: PstreamFormat,
hook: Option<ReadHook>,
) -> Result<Robj>
fn from_reader<R: Read>( reader: &mut R, format: PstreamFormat, hook: Option<ReadHook>, ) -> Result<Robj>
Write
trait.
version
should probably be 3.Source§impl MatrixConversions for Robj
impl MatrixConversions for Robj
Source§impl<Rhs> Mul<Rhs> for Robj
impl<Rhs> Mul<Rhs> for Robj
Source§fn mul(self, rhs: Rhs) -> Self::Output
fn mul(self, rhs: Rhs) -> Self::Output
Multiply two R objects, consuming the left hand side. panics on error.
use extendr_api::prelude::*;
test! {
// lhs and rhs get dropped here
let lhs = r!([10.0, 20.0]);
let rhs = r!([1.0, 2.0]);
assert_eq!(lhs * rhs, r!([10.0, 40.0]));
// lhs gets dropped and rhs is a temporary object.
let lhs = r!([1.0, 2.0]);
assert_eq!(lhs * 10.0, r!([10.0, 20.0]));
// Only lhs gets dropped.
let lhs = r!([10.0, 20.0]);
let rhs = r!([1.0, 2.0]);
assert_eq!(lhs * &rhs, r!([10.0, 40.0]));
}
Source§impl Operators for Robj
impl Operators for Robj
Source§impl Rinternals for Robj
impl Rinternals for Robj
Source§fn is_logical(&self) -> bool
fn is_logical(&self) -> bool
Source§fn is_complex(&self) -> bool
fn is_complex(&self) -> bool
Source§fn is_expressions(&self) -> bool
fn is_expressions(&self) -> bool
Source§fn is_environment(&self) -> bool
fn is_environment(&self) -> bool
Source§fn is_promise(&self) -> bool
fn is_promise(&self) -> bool
Source§fn is_external_pointer(&self) -> bool
fn is_external_pointer(&self) -> bool
Source§fn get_current_srcref(val: i32) -> Robj
fn get_current_srcref(val: i32) -> Robj
Source§fn get_src_filename(&self) -> Robj
fn get_src_filename(&self) -> Robj
Source§fn as_character_vector(&self) -> Robj
fn as_character_vector(&self) -> Robj
Source§fn coerce_vector(&self, sexptype: SEXPTYPE) -> Robj
fn coerce_vector(&self, sexptype: SEXPTYPE) -> Robj
Source§fn pair_to_vector_list(&self) -> Robj
fn pair_to_vector_list(&self) -> Robj
Source§fn vector_to_pair_list(&self) -> Robj
fn vector_to_pair_list(&self) -> Robj
Source§fn as_character_factor(&self) -> Robj
fn as_character_factor(&self) -> Robj
Source§fn duplicate(&self) -> Robj
fn duplicate(&self) -> Robj
Source§fn find_function<K: TryInto<Symbol, Error = Error>>(
&self,
key: K,
) -> Result<Robj>
fn find_function<K: TryInto<Symbol, Error = Error>>( &self, key: K, ) -> Result<Robj>
Source§fn find_var<K: TryInto<Symbol, Error = Error>>(&self, key: K) -> Result<Robj>
fn find_var<K: TryInto<Symbol, Error = Error>>(&self, key: K) -> Result<Robj>
Source§fn xlengthgets(&self, new_len: usize) -> Result<Robj>
fn xlengthgets(&self, new_len: usize) -> Result<Robj>
Source§fn alloc_vector(sexptype: SEXPTYPE, len: usize) -> Robj
fn alloc_vector(sexptype: SEXPTYPE, len: usize) -> Robj
Source§fn is_function(&self) -> bool
fn is_function(&self) -> bool
Source§fn is_integer(&self) -> bool
fn is_integer(&self) -> bool
Source§fn is_language(&self) -> bool
fn is_language(&self) -> bool
Source§fn is_pairlist(&self) -> bool
fn is_pairlist(&self) -> bool
Source§fn is_number(&self) -> bool
fn is_number(&self) -> bool
Source§fn is_primitive(&self) -> bool
fn is_primitive(&self) -> bool
Source§fn is_user_binop(&self) -> bool
fn is_user_binop(&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 is_vectorizable(&self) -> bool
fn is_vectorizable(&self) -> bool
fn is_missing_arg(&self) -> bool
fn is_unbound_value(&self) -> bool
fn is_package_env(&self) -> bool
fn package_env_name(&self) -> Robj
fn is_namespace_env(&self) -> bool
fn namespace_env_spec(&self) -> Robj
Source§fn is_altinteger(&self) -> bool
fn is_altinteger(&self) -> bool
true
if this is an integer ALTREP object.Source§fn is_altreal(&self) -> bool
fn is_altreal(&self) -> bool
true
if this is an real ALTREP object.Source§fn is_altlogical(&self) -> bool
fn is_altlogical(&self) -> bool
true
if this is an logical ALTREP object.Source§fn is_altstring(&self) -> bool
fn is_altstring(&self) -> bool
true
if this is an integer ALTREP object.Source§fn is_altlist(&self) -> bool
fn is_altlist(&self) -> bool
true
if this is an integer ALTREP object.Source§impl Slices for Robj
impl Slices for Robj
Source§unsafe fn as_typed_slice_raw<T>(&self) -> &[T]
unsafe fn as_typed_slice_raw<T>(&self) -> &[T]
Source§unsafe fn as_typed_slice_raw_mut<T>(&mut self) -> &mut [T]
unsafe fn as_typed_slice_raw_mut<T>(&mut self) -> &mut [T]
Source§impl<Rhs> Sub<Rhs> for Robj
impl<Rhs> Sub<Rhs> for Robj
Source§fn sub(self, rhs: Rhs) -> Self::Output
fn sub(self, rhs: Rhs) -> Self::Output
Subtract two R objects, consuming the left hand side. panics on error.
use extendr_api::prelude::*;
test! {
// lhs and rhs get dropped here
let lhs = r!([10, 20]);
let rhs = r!([1, 2]);
assert_eq!(lhs - rhs, r!([9, 18]));
// lhs gets dropped and rhs is a temporary object.
let lhs = r!([1000, 2000]);
assert_eq!(lhs - 1, r!([999, 1999]));
// Only lhs gets dropped.
let lhs = r!([10, 20]);
let rhs = r!([1, 2]);
assert_eq!(lhs - &rhs, r!([9, 18]));
}
Source§impl<T: 'static> TryFrom<&Robj> for &ExternalPtr<T>
impl<T: 'static> TryFrom<&Robj> for &ExternalPtr<T>
Source§impl TryFrom<&Robj> for Environment
impl TryFrom<&Robj> for Environment
Source§impl TryFrom<&Robj> for Expressions
impl TryFrom<&Robj> for Expressions
Source§impl<T: 'static> TryFrom<&Robj> for ExternalPtr<T>
impl<T: 'static> TryFrom<&Robj> for ExternalPtr<T>
Source§impl<'a, T> TryFrom<&'a Robj> for Nullable<T>
impl<'a, T> TryFrom<&'a Robj> for Nullable<T>
Source§fn try_from(robj: &'a Robj) -> Result<Self, Self::Error>
fn try_from(robj: &'a Robj) -> Result<Self, Self::Error>
Convert an object that may be null to a rust type.
use extendr_api::prelude::*;
test! {
let s1 = r!(1);
let n1 = <Nullable<i32>>::try_from(&s1)?;
assert_eq!(n1, Nullable::NotNull(1));
let snull = r!(NULL);
let nnull = <Nullable<i32>>::try_from(&snull)?;
assert_eq!(nnull, Nullable::Null);
}
Source§impl TryFrom<&Robj> for PairlistIter
impl TryFrom<&Robj> for PairlistIter
Source§impl TryFrom<&Robj> for Vec<Rfloat>
impl TryFrom<&Robj> for Vec<Rfloat>
Source§impl TryFrom<&Robj> for Vec<f64>
impl TryFrom<&Robj> for Vec<f64>
Source§impl<T: 'static> TryFrom<&mut Robj> for &mut ExternalPtr<T>
impl<T: 'static> TryFrom<&mut Robj> for &mut ExternalPtr<T>
Source§impl<T: 'static> TryFrom<Robj> for &ExternalPtr<T>
impl<T: 'static> TryFrom<Robj> for &ExternalPtr<T>
Source§impl<T: 'static> TryFrom<Robj> for &mut ExternalPtr<T>
impl<T: 'static> TryFrom<Robj> for &mut ExternalPtr<T>
Source§impl TryFrom<Robj> for Environment
impl TryFrom<Robj> for Environment
Source§impl TryFrom<Robj> for Expressions
impl TryFrom<Robj> for Expressions
Source§impl<T: 'static> TryFrom<Robj> for ExternalPtr<T>
impl<T: 'static> TryFrom<Robj> for ExternalPtr<T>
Source§impl<T> TryFrom<Robj> for Nullable<T>
impl<T> TryFrom<Robj> for Nullable<T>
Source§fn try_from(robj: Robj) -> Result<Self, Self::Error>
fn try_from(robj: Robj) -> Result<Self, Self::Error>
Convert an object that may be null to a rust type.
use extendr_api::prelude::*;
test! {
let s1 = r!(1);
let n1 = <Nullable<i32>>::try_from(s1)?;
assert_eq!(n1, Nullable::NotNull(1));
let snull = r!(NULL);
let nnull = <Nullable<i32>>::try_from(snull)?;
assert_eq!(nnull, Nullable::Null);
}
Source§impl<'de> VariantAccess<'de> for &'de Robj
impl<'de> VariantAccess<'de> for &'de Robj
Source§type Error = Error
type Error = Error
EnumAccess
.Source§fn unit_variant(self) -> Result<()>
fn unit_variant(self) -> Result<()>
Source§fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value>where
T: DeserializeSeed<'de>,
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value>where
T: DeserializeSeed<'de>,
Source§fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value>where
V: Visitor<'de>,
Source§fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value>where
V: Visitor<'de>,
Source§fn newtype_variant<T>(self) -> Result<T, Self::Error>where
T: Deserialize<'de>,
fn newtype_variant<T>(self) -> Result<T, Self::Error>where
T: Deserialize<'de>,
Auto Trait Implementations§
impl Freeze for Robj
impl RefUnwindSafe for Robj
impl !Send for Robj
impl !Sync for Robj
impl Unpin for Robj
impl UnwindSafe for Robj
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more