logo
pub trait Operators: Rinternals {
    fn dollar<T>(&self, symbol: T) -> Result<Robj>
    where
        T: AsRef<str>
, { ... } fn slice<T>(&self, rhs: T) -> Result<Robj>
    where
        T: Into<Robj>
, { ... } fn index<T>(&self, rhs: T) -> Result<Robj>
    where
        T: Into<Robj>
, { ... } fn tilde<T>(&self, rhs: T) -> Result<Robj>
    where
        T: Into<Robj>
, { ... } fn double_colon<T>(&self, rhs: T) -> Result<Robj>
    where
        T: Into<Robj>
, { ... } fn call(&self, args: Pairlist) -> Result<Robj> { ... } }
Expand description

The following impls add operators to Robj.

Provided methods

Do the equivalent of x$y

use extendr_api::prelude::*;
test! {
let env = Environment::from_pairs(global_env(),
   vec![("a".to_string(), r!(1)), ("b".to_string(), r!(2))]);
assert_eq!(env.dollar("a").unwrap(), r!(1));
assert_eq!(env.dollar("b").unwrap(), r!(2));
}

Do the equivalent of x[y]

use extendr_api::prelude::*;
test! {
let vec = r!([10, 20, 30]);
assert_eq!(vec.slice(2).unwrap(), r!(20));
assert_eq!(vec.slice(2..=3).unwrap(), r!([20, 30]));
}

Do the equivalent of x[[y]]

use extendr_api::prelude::*;
test! {
let vec = r!([10, 20, 30]);
assert_eq!(vec.index(2).unwrap(), r!(20));
assert_eq!(vec.index(2..=3).is_err(), true);
}

Do the equivalent of x ~ y

use extendr_api::prelude::*;
test! {
    let x = r!(Symbol::from_string("x"));
    let y = r!(Symbol::from_string("y"));
    let tilde = x.tilde(y).unwrap();
    assert_eq!(tilde.inherits("formula"), true);
}

Do the equivalent of x :: y

use extendr_api::prelude::*;
test! {
    let base = r!(Symbol::from_string("base"));
    let list = r!(Symbol::from_string("list"));
    let base_list = base.double_colon(list).unwrap();
    assert_eq!(base_list.is_function(), true);
}

Do the equivalent of x(a, b, c)

use extendr_api::prelude::*;
test! {
    let function = R!("function(a, b) a + b").unwrap();
    assert_eq!(function.is_function(), true);
    assert_eq!(function.call(pairlist!(a=1, b=2)).unwrap(), r!(3));
}

Implementors

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.

dollar() etc.