pub trait Conversions: GetSexp {
// Provided methods
fn as_symbol(&self) -> Option<Symbol> { ... }
fn as_char(&self) -> Option<Rstr> { ... }
fn as_raw(&self) -> Option<Raw> { ... }
fn as_language(&self) -> Option<Language> { ... }
fn as_pairlist(&self) -> Option<Pairlist> { ... }
fn as_list(&self) -> Option<List> { ... }
fn as_expressions(&self) -> Option<Expressions> { ... }
fn as_environment(&self) -> Option<Environment> { ... }
fn as_function(&self) -> Option<Function> { ... }
fn as_promise(&self) -> Option<Promise> { ... }
}
Provided Methods§
Sourcefn as_symbol(&self) -> Option<Symbol>
fn as_symbol(&self) -> Option<Symbol>
Convert a symbol object to a Symbol wrapper.
use extendr_api::prelude::*;
test! {
let fred = sym!(fred);
assert_eq!(fred.as_symbol(), Some(Symbol::from_string("fred")));
}
Sourcefn as_char(&self) -> Option<Rstr>
fn as_char(&self) -> Option<Rstr>
Convert a CHARSXP
object to a Rstr
wrapper.
use extendr_api::prelude::*;
test! {
let fred = Rstr::from_string("fred");
assert_eq!(fred.as_char(), Some(Rstr::from_string("fred")));
}
Sourcefn as_raw(&self) -> Option<Raw>
fn as_raw(&self) -> Option<Raw>
Convert a raw object to a Rstr wrapper.
use extendr_api::prelude::*;
test! {
let bytes = r!(Raw::from_bytes(&[1, 2, 3]));
assert_eq!(bytes.len(), 3);
assert_eq!(bytes.as_raw(), Some(Raw::from_bytes(&[1, 2, 3])));
}
Sourcefn as_language(&self) -> Option<Language>
fn as_language(&self) -> Option<Language>
Convert a language object to a Language wrapper.
use extendr_api::prelude::*;
test! {
let call_to_xyz = r!(Language::from_values(&[r!(Symbol::from_string("xyz")), r!(1), r!(2)]));
assert_eq!(call_to_xyz.is_language(), true);
assert_eq!(call_to_xyz.len(), 3);
}
Sourcefn as_pairlist(&self) -> Option<Pairlist>
fn as_pairlist(&self) -> Option<Pairlist>
Convert a pair list object (LISTSXP) to a Pairlist wrapper.
use extendr_api::prelude::*;
test! {
let names_and_values = vec![("a", r!(1)), ("b", r!(2)), ("", r!(3))];
let pairlist = Pairlist::from_pairs(names_and_values);
let robj = r!(pairlist.clone());
assert_eq!(robj.as_pairlist().unwrap(), pairlist);
}
Sourcefn as_list(&self) -> Option<List>
fn as_list(&self) -> Option<List>
Convert a list object (VECSXP) to a List wrapper.
use extendr_api::prelude::*;
test! {
let list = r!(List::from_values(&[r!(0), r!(1), r!(2)]));
assert_eq!(list.is_list(), true);
}
Sourcefn as_expressions(&self) -> Option<Expressions>
fn as_expressions(&self) -> Option<Expressions>
Convert an expression object (EXPRSXP) to a Expr wrapper.
use extendr_api::prelude::*;
test! {
let expr = r!(Expressions::from_values(&[r!(0), r!(1), r!(2)]));
assert_eq!(expr.is_expressions(), true);
assert_eq!(expr.as_expressions(), Some(Expressions::from_values(vec![r!(0), r!(1), r!(2)])));
}
Sourcefn as_environment(&self) -> Option<Environment>
fn as_environment(&self) -> Option<Environment>
Convert an environment object (ENVSXP) to a Env wrapper.
use extendr_api::prelude::*;
test! {
let names_and_values = (0..100).map(|i| (format!("n{}", i), i));
let env = Environment::from_pairs(global_env(), names_and_values);
let expr = env.clone();
assert_eq!(expr.len(), 100);
let env2 = expr.as_environment().unwrap();
assert_eq!(env2.len(), 100);
}
Sourcefn as_function(&self) -> Option<Function>
fn as_function(&self) -> Option<Function>
Convert a function object (CLOSXP) to a Function wrapper.
use extendr_api::prelude::*;
test! {
let func = R!("function(a,b) a + b").unwrap();
println!("{:?}", func.as_function());
}
Sourcefn as_promise(&self) -> Option<Promise>
fn as_promise(&self) -> Option<Promise>
Get a wrapper for a promise.
Implementors§
impl Conversions for Robj
impl Conversions for Altrep
as_*()
impl Conversions for Complexes
as_*()
impl Conversions for Doubles
as_*()
impl Conversions for Environment
as_*()
impl Conversions for Expressions
as_*()
impl Conversions for Function
as_*()
impl Conversions for Integers
as_*()
impl Conversions for Language
as_*()
impl Conversions for List
as_*()
impl Conversions for Logicals
as_*()
impl Conversions for Pairlist
as_*()
impl Conversions for Primitive
as_*()
impl Conversions for Promise
as_*()
impl Conversions for Raw
as_*()
impl Conversions for Rstr
as_*()
impl Conversions for S4
as_*()
impl Conversions for Strings
as_*()
impl Conversions for Symbol
as_*()
impl<T> Conversions for Dataframe<T>
as_*()
impl<T> Conversions for ExternalPtr<T>
as_*()