logo
pub trait Types: GetSexp {
    fn rtype(&self) -> Rtype { ... }
    fn as_any(&self) -> Rany<'_> { ... }
}

Provided methods

Get the type of an R object.

use extendr_api::prelude::*;
test! {
    assert_eq!(r!(NULL).rtype(), Rtype::Null);
    assert_eq!(sym!(xyz).rtype(), Rtype::Symbol);
    assert_eq!(r!(Pairlist::from_pairs(vec![("a", r!(1))])).rtype(), Rtype::Pairlist);
    assert_eq!(R!("function() {}")?.rtype(), Rtype::Function);
    assert_eq!(Environment::new_with_parent(global_env()).rtype(), Rtype::Environment);
    assert_eq!(lang!("+", 1, 2).rtype(), Rtype::Language);
    assert_eq!(r!(Primitive::from_string("if")).rtype(), Rtype::Special);
    assert_eq!(r!(Primitive::from_string("+")).rtype(), Rtype::Builtin);
    assert_eq!(r!(Rstr::from_string("hello")).rtype(), Rtype::Rstr);
    assert_eq!(r!(TRUE).rtype(), Rtype::Logicals);
    assert_eq!(r!(1).rtype(), Rtype::Integers);
    assert_eq!(r!(1.0).rtype(), Rtype::Doubles);
    assert_eq!(r!("1").rtype(), Rtype::Strings);
    assert_eq!(r!(List::from_values(&[1, 2])).rtype(), Rtype::List);
    assert_eq!(parse("x + y")?.rtype(), Rtype::Expressions);
    assert_eq!(r!(Raw::from_bytes(&[1_u8, 2, 3])).rtype(), Rtype::Raw);
}

Implementors

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()

rtype() and rany()