extendr_api::robj

Trait Operators

Source
pub trait Operators: Rinternals {
    // Provided methods
    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§

Source

fn dollar<T>(&self, symbol: T) -> Result<Robj>
where T: AsRef<str>,

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));
}
Source

fn slice<T>(&self, rhs: T) -> Result<Robj>
where T: Into<Robj>,

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

fn index<T>(&self, rhs: T) -> Result<Robj>
where T: Into<Robj>,

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);
}
Source

fn tilde<T>(&self, rhs: T) -> Result<Robj>
where T: Into<Robj>,

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);
}
Source

fn double_colon<T>(&self, rhs: T) -> Result<Robj>
where T: Into<Robj>,

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);
}
Source

fn call(&self, args: Pairlist) -> Result<Robj>

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Operators for Altrep

dollar() etc.

Source§

impl Operators for Complexes

dollar() etc.

Source§

impl Operators for Doubles

dollar() etc.

Source§

impl Operators for Environment

dollar() etc.

Source§

impl Operators for Expressions

dollar() etc.

Source§

impl Operators for Function

dollar() etc.

Source§

impl Operators for Integers

dollar() etc.

Source§

impl Operators for Language

dollar() etc.

Source§

impl Operators for List

dollar() etc.

Source§

impl Operators for Logicals

dollar() etc.

Source§

impl Operators for Pairlist

dollar() etc.

Source§

impl Operators for Primitive

dollar() etc.

Source§

impl Operators for Promise

dollar() etc.

Source§

impl Operators for Raw

dollar() etc.

Source§

impl Operators for Rstr

dollar() etc.

Source§

impl Operators for S4

dollar() etc.

Source§

impl Operators for Strings

dollar() etc.

Source§

impl Operators for Symbol

dollar() etc.

Source§

impl Operators for Robj

Source§

impl<T> Operators for Dataframe<T>

dollar() etc.

Source§

impl<T> Operators for ExternalPtr<T>

dollar() etc.