logo
pub trait RobjItertools: Iterator {
    fn collect_robj(self) -> Robj
    where
        Self: Iterator,
        Self: Sized,
        Self::Item: ToVectorValue
, { ... } }
Expand description

Extensions to iterators for R objects including RobjItertools::collect_robj().

Provided methods

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

Implementors