Struct extendr_api::robj::Robj
source · [−]pub struct Robj { /* private fields */ }
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.
Implementations
sourceimpl 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.
sourceimpl 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
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
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
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
sourceimpl<Rhs> Add<Rhs> for Robj where
Rhs: Into<Robj>,
impl<Rhs> Add<Rhs> for Robj where
Rhs: Into<Robj>,
sourcefn 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]));
}
sourceimpl AsStrIter for Robj
impl AsStrIter for Robj
sourcefn as_str_iter(&self) -> Option<StrIter>
fn as_str_iter(&self) -> Option<StrIter>
Get an iterator over a string vector. Returns None if the object is not a string vector but works for factors. Read more
sourceimpl<'a> AsTypedSlice<'a, Complex<f64>> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, Complex<f64>> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, Rbool> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, Rbool> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, Rcomplex> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, Rcomplex> for Robj where
Self: 'a,
fn as_typed_slice(&self) -> Option<&'a [Rcomplex]>
fn as_typed_slice_mut(&mut self) -> Option<&'a mut [Rcomplex]>
sourceimpl<'a> AsTypedSlice<'a, Rcplx> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, Rcplx> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, Rfloat> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, Rfloat> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, Rint> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, Rint> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, Robj> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, Robj> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, Rstr> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, Rstr> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, f64> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, f64> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, i32> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, i32> for Robj where
Self: 'a,
sourceimpl<'a> AsTypedSlice<'a, u8> for Robj where
Self: 'a,
impl<'a> AsTypedSlice<'a, u8> for Robj where
Self: 'a,
sourceimpl Attributes for Robj
impl Attributes for Robj
sourcefn get_attrib<'a, N>(&self, name: N) -> Option<Robj> where
Self: 'a,
Robj: From<N> + 'a,
fn get_attrib<'a, N>(&self, name: N) -> Option<Robj> where
Self: 'a,
Robj: From<N> + 'a,
Get a specific attribute as a borrowed robj if it exists. Read more
sourcefn has_attrib<'a, N>(&self, name: N) -> bool where
Self: 'a,
Robj: From<N> + 'a,
fn has_attrib<'a, N>(&self, name: N) -> bool where
Self: 'a,
Robj: From<N> + 'a,
Return true if an attribute exists.
sourcefn set_attrib<N, V>(&self, name: N, value: V) -> Result<Robj> where
N: Into<Robj>,
V: Into<Robj>,
fn set_attrib<N, V>(&self, name: N, value: V) -> Result<Robj> where
N: Into<Robj>,
V: Into<Robj>,
Set a specific attribute and return the object. Read more
sourcefn names(&self) -> Option<StrIter>
fn names(&self) -> Option<StrIter>
Get the names attribute as a string iterator if one exists. Read more
sourcefn set_names<T>(&mut self, names: T) -> Result<Robj> where
T: IntoIterator,
T::IntoIter: ExactSizeIterator,
T::Item: ToVectorValue + AsRef<str>,
fn set_names<T>(&mut self, names: T) -> Result<Robj> where
T: IntoIterator,
T::IntoIter: ExactSizeIterator,
T::Item: ToVectorValue + AsRef<str>,
Set the names attribute from a string iterator. Read more
sourcefn dim(&self) -> Option<Integers>
fn dim(&self) -> Option<Integers>
Get the dim attribute as an integer iterator if one exists. Read more
sourcefn dimnames(&self) -> Option<ListIter>
fn dimnames(&self) -> Option<ListIter>
Get the dimnames attribute as a list iterator if one exists. Read more
sourcefn class(&self) -> Option<StrIter>
fn class(&self) -> Option<StrIter>
Get the class attribute as a string iterator if one exists. Read more
sourcefn set_class<T>(&self, class: T) -> Result<Robj> where
T: IntoIterator,
T::IntoIter: ExactSizeIterator,
T::Item: ToVectorValue + AsRef<str>,
fn set_class<T>(&self, class: T) -> Result<Robj> where
T: IntoIterator,
T::IntoIter: ExactSizeIterator,
T::Item: ToVectorValue + AsRef<str>,
Set the class attribute from a string iterator, returning a new object. Read more
sourceimpl Conversions for Robj
impl Conversions for Robj
sourcefn as_language(&self) -> Option<Language>
fn as_language(&self) -> Option<Language>
Convert a language object to a Language wrapper. Read more
sourcefn as_pairlist(&self) -> Option<Pairlist>
fn as_pairlist(&self) -> Option<Pairlist>
Convert a pair list object (LISTSXP) to a Pairlist wrapper. Read more
sourcefn as_expressions(&self) -> Option<Expressions>
fn as_expressions(&self) -> Option<Expressions>
Convert an expression object (EXPRSXP) to a Expr wrapper. Read more
sourcefn as_environment(&self) -> Option<Environment>
fn as_environment(&self) -> Option<Environment>
Convert an environment object (ENVSXP) to a Env wrapper. Read more
sourcefn as_function(&self) -> Option<Function>
fn as_function(&self) -> Option<Function>
Convert a function object (CLOSXP) to a Function wrapper. Read more
sourcefn as_promise(&self) -> Option<Promise>
fn as_promise(&self) -> Option<Promise>
Get a wrapper for a promise.
sourceimpl<'de> Deserialize<'de> for Robj
impl<'de> Deserialize<'de> for Robj
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'de> Deserializer<'de> for &'de Robj
impl<'de> Deserializer<'de> for &'de Robj
type Error = Error
type Error = Error
The error type that can be returned if some error occurs during deserialization. Read more
sourcefn 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>,
Require the Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a unit value.
sourcefn 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>,
Hint that the Deserialize
type is expecting a bool
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting an i8
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting an i16
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting an i32
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting an i64
value.
sourcefn deserialize_i128<V>(self, visitor: V) -> Result<V::Value> where
V: Visitor<'de>,
fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an i128
value. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a u8
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting a u16
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting a u32
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting a u64
value.
sourcefn deserialize_u128<V>(self, visitor: V) -> Result<V::Value> where
V: Visitor<'de>,
fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an u128
value. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a f32
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting a f64
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting a char
value.
sourcefn 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>,
Hint that the Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting an optional value. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a unit struct with a
particular name. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a newtype struct with a
particular name. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a sequence of values and
knows how many values there are without looking at the serialized data. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a tuple struct with a
particular name and number of fields. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting a sequence of values.
sourcefn 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>,
Hint that the Deserialize
type is expecting a map of key-value pairs.
sourcefn 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>,
Hint that the Deserialize
type is expecting a struct with a particular
name and fields. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting the name of a struct
field or the discriminant of an enum variant. Read more
sourcefn 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>,
Hint that the Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read more
sourcefn 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>,
Hint that the Deserialize
type is expecting an enum value with a
particular name and possible variants. Read more
sourcefn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Determine whether Deserialize
implementations should expect to
deserialize their human-readable form. Read more
sourceimpl<Rhs> Div<Rhs> for Robj where
Rhs: Into<Robj>,
impl<Rhs> Div<Rhs> for Robj where
Rhs: Into<Robj>,
sourcefn 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]));
}
sourceimpl<'de> EnumAccess<'de> for &'de Robj
impl<'de> EnumAccess<'de> for &'de Robj
type Error = Error
type Error = Error
The error type that can be returned if some error occurs during deserialization. Read more
type Variant = Self
type Variant = Self
The Visitor
that will be used to deserialize the content of the enum
variant. Read more
sourcefn 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 more
sourceimpl Eval for Robj
impl Eval for Robj
sourcefn eval(&self) -> Result<Robj>
fn eval(&self) -> Result<Robj>
Evaluate the expression in R and return an error or an R object. Read more
sourcefn eval_with_env(&self, env: &Environment) -> Result<Robj>
fn eval_with_env(&self, env: &Environment) -> Result<Robj>
Evaluate the expression in R and return an error or an R object. Read more
sourcefn eval_blind(&self) -> Robj
fn eval_blind(&self) -> Robj
Evaluate the expression and return NULL or an R object. Read more
sourceimpl From<&'_ Environment> for Robj
impl From<&'_ Environment> for Robj
sourcefn from(val: &Environment) -> Self
fn from(val: &Environment) -> Self
Make an robj from a wrapper.
sourceimpl From<&'_ Expressions> for Robj
impl From<&'_ Expressions> for Robj
sourcefn from(val: &Expressions) -> Self
fn from(val: &Expressions) -> Self
Make an robj from a wrapper.
sourceimpl<'a, T> From<&'_ Vec<T, Global>> for Robj where
Self: 'a,
T: Clone + 'a,
T: ToVectorValue,
impl<'a, T> From<&'_ Vec<T, Global>> for Robj where
Self: 'a,
T: Clone + 'a,
T: ToVectorValue,
sourceimpl From<Environment> for Robj
impl From<Environment> for Robj
sourcefn from(val: Environment) -> Self
fn from(val: Environment) -> Self
Make an robj from a wrapper.
sourceimpl From<Expressions> for Robj
impl From<Expressions> for Robj
sourcefn from(val: Expressions) -> Self
fn from(val: Expressions) -> Self
Make an robj from a wrapper.
sourceimpl<T: Any + Debug> From<ExternalPtr<T>> for Robj
impl<T: Any + Debug> From<ExternalPtr<T>> for Robj
sourcefn from(val: ExternalPtr<T>) -> Self
fn from(val: ExternalPtr<T>) -> Self
Converts to this type from the input type.
sourceimpl From<PairlistIter> for Robj
impl From<PairlistIter> for Robj
sourcefn from(iter: PairlistIter) -> Self
fn from(iter: PairlistIter) -> Self
You can return a PairlistIter from a function.
sourceimpl<T> From<Range<T>> for Robj where
Range<T>: RobjItertools,
<Range<T> as Iterator>::Item: ToVectorValue,
T: ToVectorValue,
impl<T> From<Range<T>> for Robj where
Range<T>: RobjItertools,
<Range<T> as Iterator>::Item: ToVectorValue,
T: ToVectorValue,
sourceimpl<T> From<RangeInclusive<T>> for Robj where
RangeInclusive<T>: RobjItertools,
<RangeInclusive<T> as Iterator>::Item: ToVectorValue,
T: ToVectorValue,
impl<T> From<RangeInclusive<T>> for Robj where
RangeInclusive<T>: RobjItertools,
<RangeInclusive<T> as Iterator>::Item: ToVectorValue,
T: ToVectorValue,
sourcefn from(val: RangeInclusive<T>) -> Self
fn from(val: RangeInclusive<T>) -> Self
Converts to this type from the input type.
sourceimpl<T> From<Result<T, Error>> for Robj where
T: Into<Robj>,
impl<T> From<Result<T, Error>> for Robj where
T: Into<Robj>,
Convert a Result to an Robj. This is used to allow
functions to use the ? operator and return Result
Panics if there is an error.
use extendr_api::prelude::*;
fn my_func() -> Result<f64> {
Ok(1.0)
}
test! {
assert_eq!(r!(my_func()), r!(1.0));
}
sourceimpl<T> From<T> for Robj where
T: ToVectorValue,
impl<T> From<T> for Robj where
T: ToVectorValue,
sourceimpl Load for Robj
impl Load for Robj
sourcefn 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>
Save an object in the R data format.
version
should probably be 3. Read more
sourcefn 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>
Save an object in the R data format to a Write
trait.
version
should probably be 3. Read more
sourceimpl MatrixConversions for Robj
impl MatrixConversions for Robj
fn as_column<'a, E: 'a>(&self) -> Option<RColumn<E>> where
Robj: AsTypedSlice<'a, E>,
fn as_matrix<'a, E: 'a>(&self) -> Option<RMatrix<E>> where
Robj: AsTypedSlice<'a, E>,
fn as_matrix3d<'a, E: 'a>(&self) -> Option<RMatrix3D<E>> where
Robj: AsTypedSlice<'a, E>,
sourceimpl<Rhs> Mul<Rhs> for Robj where
Rhs: Into<Robj>,
impl<Rhs> Mul<Rhs> for Robj where
Rhs: Into<Robj>,
sourcefn 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]));
}
sourceimpl Operators for Robj
impl Operators for Robj
sourcefn dollar<T>(&self, symbol: T) -> Result<Robj> where
T: AsRef<str>,
fn dollar<T>(&self, symbol: T) -> Result<Robj> where
T: AsRef<str>,
Do the equivalent of x$y Read more
sourcefn slice<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
fn slice<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
Do the equivalent of x[y]
Read more
sourcefn index<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
fn index<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
Do the equivalent of x[[y]]
Read more
sourcefn tilde<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
fn tilde<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
Do the equivalent of x ~ y Read more
sourceimpl Rinternals for Robj
impl Rinternals for Robj
sourcefn is_logical(&self) -> bool
fn is_logical(&self) -> bool
Return true if this is a boolean (logical) vector
sourcefn is_complex(&self) -> bool
fn is_complex(&self) -> bool
Return true if this is a complex vector.
sourcefn is_expressions(&self) -> bool
fn is_expressions(&self) -> bool
Return true if this is an expression.
sourcefn is_environment(&self) -> bool
fn is_environment(&self) -> bool
Return true if this is an environment.
sourcefn is_promise(&self) -> bool
fn is_promise(&self) -> bool
Return true if this is an environment.
sourcefn is_external_pointer(&self) -> bool
fn is_external_pointer(&self) -> bool
Return true if this is an expression.
sourcefn get_current_srcref(val: i32) -> Robj
fn get_current_srcref(val: i32) -> Robj
Get the source ref.
sourcefn get_src_filename(&self) -> Robj
fn get_src_filename(&self) -> Robj
Get the source filename.
sourcefn as_character_vector(&self) -> Robj
fn as_character_vector(&self) -> Robj
Convert to a string vector.
sourcefn coerce_vector(&self, sexptype: u32) -> Robj
fn coerce_vector(&self, sexptype: u32) -> Robj
Convert to vectors of many kinds.
sourcefn pair_to_vector_list(&self) -> Robj
fn pair_to_vector_list(&self) -> Robj
Convert a pairlist (LISTSXP) to a vector list (VECSXP).
sourcefn vector_to_pair_list(&self) -> Robj
fn vector_to_pair_list(&self) -> Robj
Convert a vector list (VECSXP) to a pair list (LISTSXP)
sourcefn as_character_factor(&self) -> Robj
fn as_character_factor(&self) -> Robj
Convert a factor to a string vector.
sourcefn alloc_matrix(sexptype: SEXPTYPE, rows: i32, cols: i32) -> Robj
fn alloc_matrix(sexptype: SEXPTYPE, rows: i32, cols: i32) -> Robj
Allocate a matrix object.
sourcefn duplicate(&self) -> Robj
fn duplicate(&self) -> Robj
Do a deep copy of this object. Note that clone() only adds a reference. Read more
sourcefn 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>
Find a function in an environment ignoring other variables. Read more
sourcefn 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>
Find a variable in an environment. Read more
sourcefn eval_promise(&self) -> Result<Robj>
fn eval_promise(&self) -> Result<Robj>
If this object is a promise, evaluate it, otherwise return the object. Read more
sourcefn xlengthgets(&self, new_len: usize) -> Result<Robj>
fn xlengthgets(&self, new_len: usize) -> Result<Robj>
Copy a vector and resize it. See. https://github.com/hadley/r-internals/blob/master/vectors.md Read more
sourcefn alloc_vector(sexptype: u32, len: usize) -> Robj
fn alloc_vector(sexptype: u32, len: usize) -> Robj
Allocated an owned object of a certain type.
sourcefn conformable(a: &Robj, b: &Robj) -> bool
fn conformable(a: &Robj, b: &Robj) -> bool
Return true if two arrays have identical dims.
sourcefn is_function(&self) -> bool
fn is_function(&self) -> bool
Return true if this is a function or a primitive (CLOSXP, BUILTINSXP or SPECIALSXP)
sourcefn is_integer(&self) -> bool
fn is_integer(&self) -> bool
Return true if this is an integer vector (INTSXP) but not a factor.
sourcefn is_language(&self) -> bool
fn is_language(&self) -> bool
Return true if this is a language object (LANGSXP).
sourcefn is_pairlist(&self) -> bool
fn is_pairlist(&self) -> bool
Return true if this is NILSXP or LISTSXP.
sourcefn is_primitive(&self) -> bool
fn is_primitive(&self) -> bool
Return true if this is a primitive function BUILTINSXP, SPECIALSXP.
sourcefn is_user_binop(&self) -> bool
fn is_user_binop(&self) -> bool
Return true if this is a user defined binop.
sourcefn is_valid_string(&self) -> bool
fn is_valid_string(&self) -> bool
Return true if this is a valid string.
sourcefn is_valid_string_f(&self) -> bool
fn is_valid_string_f(&self) -> bool
Return true if this is a valid string.
sourcefn is_vector_atomic(&self) -> bool
fn is_vector_atomic(&self) -> bool
Return true if this is an atomic vector.
sourcefn is_vector_list(&self) -> bool
fn is_vector_list(&self) -> bool
Return true if this is a vector list.
sourcefn is_vectorizable(&self) -> bool
fn is_vectorizable(&self) -> bool
Return true if this is can be made into a vector.
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
sourcefn is_altinteger(&self) -> bool
fn is_altinteger(&self) -> bool
Returns true
if this is an integer ALTREP object.
sourcefn is_altreal(&self) -> bool
fn is_altreal(&self) -> bool
Returns true
if this is an real ALTREP object.
sourcefn is_altlogical(&self) -> bool
fn is_altlogical(&self) -> bool
Returns true
if this is an logical ALTREP object.
sourcefn is_altstring(&self) -> bool
fn is_altstring(&self) -> bool
Returns true
if this is an integer ALTREP object.
sourceimpl Slices for Robj
impl Slices for Robj
sourceimpl<Rhs> Sub<Rhs> for Robj where
Rhs: Into<Robj>,
impl<Rhs> Sub<Rhs> for Robj where
Rhs: Into<Robj>,
sourcefn 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]));
}
sourceimpl<A, S, D> TryFrom<&'_ ArrayBase<S, D>> for Robj where
S: Data<Elem = A>,
A: Copy + ToVectorValue,
D: Dimension,
impl<A, S, D> TryFrom<&'_ ArrayBase<S, D>> for Robj where
S: Data<Elem = A>,
A: Copy + ToVectorValue,
D: Dimension,
sourceimpl TryFrom<&'_ Robj> for Vec<f64>
impl TryFrom<&'_ Robj> for Vec<f64>
sourceimpl TryFrom<&'_ Robj> for Vec<Rfloat>
impl TryFrom<&'_ Robj> for Vec<Rfloat>
sourceimpl<T> TryFrom<&'_ Robj> for FromList<Vec<T>> where
T: TryFrom<Robj>,
<T as TryFrom<Robj>>::Error: Into<Error>,
impl<T> TryFrom<&'_ Robj> for FromList<Vec<T>> where
T: TryFrom<Robj>,
<T as TryFrom<Robj>>::Error: Into<Error>,
sourceimpl TryFrom<&'_ Robj> for PairlistIter
impl TryFrom<&'_ Robj> for PairlistIter
sourceimpl TryFrom<&'_ Robj> for Environment
impl TryFrom<&'_ Robj> for Environment
sourceimpl TryFrom<&'_ Robj> for Expressions
impl TryFrom<&'_ Robj> for Expressions
sourceimpl<T> TryFrom<Robj> for FromList<Vec<T>> where
T: TryFrom<Robj>,
<T as TryFrom<Robj>>::Error: Into<Error>,
impl<T> TryFrom<Robj> for FromList<Vec<T>> where
T: TryFrom<Robj>,
<T as TryFrom<Robj>>::Error: Into<Error>,
sourceimpl TryFrom<Robj> for Environment
impl TryFrom<Robj> for Environment
sourceimpl TryFrom<Robj> for Expressions
impl TryFrom<Robj> for Expressions
sourceimpl<'de> VariantAccess<'de> for &'de Robj
impl<'de> VariantAccess<'de> for &'de Robj
type Error = Error
type Error = Error
The error type that can be returned if some error occurs during
deserialization. Must match the error type of our EnumAccess
. Read more
sourcefn unit_variant(self) -> Result<()>
fn unit_variant(self) -> Result<()>
Called when deserializing a variant with no values. Read more
sourcefn 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>,
Called when deserializing a variant with a single value. Read more
sourcefn 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>,
Called when deserializing a tuple-like variant. Read more
sourcefn 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>,
Called when deserializing a struct-like variant. Read more
sourcefn 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>,
Called when deserializing a variant with a single value. Read more
Auto Trait Implementations
impl RefUnwindSafe for Robj
impl !Send for Robj
impl !Sync for Robj
impl Unpin for Robj
impl UnwindSafe for Robj
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more