Trait extendr_api::robj::RobjItertools

source ·
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§

source

fn collect_robj(self) -> Robj
where Self: Iterator + Sized, Self::Item: ToVectorValue,

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"]));
}
source

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>,

Collects an iterable into an RArray. The iterable must yield items column by column (aka Fortan order)

§Arguments
  • dims - an array containing the length of each dimension

Implementors§

source§

impl<T> RobjItertools for T
where T: Iterator,