pub trait RobjItertools: Iterator {
// Provided methods
fn collect_robj(self) -> Robj
where Self: Iterator + Sized,
Self::Item: ToVectorValue { ... }
fn collect_rarray<const LEN: usize>(
self,
dims: [usize; LEN],
) -> Result<RArray<Self::Item, [usize; LEN]>>
where Self: Iterator + Sized,
Self::Item: ToVectorValue,
Robj: for<'a> AsTypedSlice<'a, Self::Item> { ... }
}
Expand description
Extensions to iterators for R objects including RobjItertools::collect_robj().
Provided Methods§
Sourcefn collect_robj(self) -> Robj
fn collect_robj(self) -> Robj
Convert a wide range of iterators to Robj.
use extendr_api::prelude::*;
test! {
// Integer iterators.
let robj = (0..3).collect_robj();
assert_eq!(robj.as_integer_vector().unwrap(), vec![0, 1, 2]);
// Logical iterators.
let robj = (0..3).map(|x| x % 2 == 0).collect_robj();
assert_eq!(robj.as_logical_vector().unwrap(), vec![TRUE, FALSE, TRUE]);
// Numeric iterators.
let robj = (0..3).map(|x| x as f64).collect_robj();
assert_eq!(robj.as_real_vector().unwrap(), vec![0., 1., 2.]);
// String iterators.
let robj = (0..3).map(|x| format!("{}", x)).collect_robj();
assert_eq!(robj.as_str_vector(), Some(vec!["0", "1", "2"]));
}