Trait extendr_api::robj::operators::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));
}

Object Safety§

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: Debug + 'static> Operators for ExternalPtr<T>

dollar() etc.