Struct extendr_api::wrapper::environment::Environment
source · [−]pub struct Environment { /* private fields */ }
Implementations
sourceimpl Environment
impl Environment
sourcepub fn new_with_parent(parent: Environment) -> Self
pub fn new_with_parent(parent: Environment) -> Self
Create a new, empty environment.
use extendr_api::prelude::*;
test! {
let env = Environment::new_with_parent(global_env());
assert_eq!(env.len(), 0);
}
sourcepub fn new_with_capacity(parent: Environment, capacity: usize) -> Self
pub fn new_with_capacity(parent: Environment, capacity: usize) -> Self
Create a new, empty environment with a reserved size.
This function will guess the hash table size if required. Use the Env{} wrapper for more detail.
use extendr_api::prelude::*;
test! {
let env = Environment::new_with_capacity(global_env(), 5);
env.set_local(sym!(a), 1);
env.set_local(sym!(b), 2);
assert_eq!(env.len(), 2);
}
sourcepub fn from_pairs<NV>(parent: Environment, names_and_values: NV) -> Self where
NV: IntoIterator,
NV::Item: SymPair,
pub fn from_pairs<NV>(parent: Environment, names_and_values: NV) -> Self where
NV: IntoIterator,
NV::Item: SymPair,
Make an R environment object.
use extendr_api::prelude::*;
use std::convert::TryInto;
test! {
let names_and_values = (0..100).map(|i| (format!("n{}", i), i));
let mut env = Environment::from_pairs(global_env(), names_and_values);
assert_eq!(env.len(), 100);
}
sourcepub fn parent(&self) -> Option<Environment>
pub fn parent(&self) -> Option<Environment>
Get the enclosing (parent) environment.
sourcepub fn set_parent(&mut self, parent: Environment) -> &mut Self
pub fn set_parent(&mut self, parent: Environment) -> &mut Self
Set the enclosing (parent) environment.
sourcepub fn set_envflags(&mut self, flags: i32) -> &mut Self
pub fn set_envflags(&mut self, flags: i32) -> &mut Self
Set the environment flags.
sourcepub fn iter(&self) -> EnvIterⓘNotable traits for EnvIterimpl Iterator for EnvIter type Item = (&'static str, Robj);
pub fn iter(&self) -> EnvIterⓘNotable traits for EnvIterimpl Iterator for EnvIter type Item = (&'static str, Robj);
Iterate over an environment.
sourcepub fn names(&self) -> impl Iterator<Item = &str>
pub fn names(&self) -> impl Iterator<Item = &str>
Get the names in an environment.
use extendr_api::prelude::*;
test! {
let names_and_values : std::collections::HashMap<_, _> = (0..4).map(|i| (format!("n{}", i), r!(i))).collect();
let env = Environment::from_pairs(global_env(), names_and_values);
assert_eq!(env.names().collect::<Vec<_>>(), vec!["n0", "n1", "n2", "n3"]);
}
sourcepub fn set_local<K: Into<Robj>, V: Into<Robj>>(&self, key: K, value: V)
pub fn set_local<K: Into<Robj>, V: Into<Robj>>(&self, key: K, value: V)
Set or define a variable in an environment.
use extendr_api::prelude::*;
test! {
let env = Environment::new_with_parent(global_env());
env.set_local(sym!(x), "harry");
env.set_local(sym!(x), "fred");
assert_eq!(env.local(sym!(x)), Ok(r!("fred")));
}
Trait Implementations
sourceimpl Clone for Environment
impl Clone for Environment
sourcefn clone(&self) -> Environment
fn clone(&self) -> Environment
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Conversions for Environment
impl Conversions for Environment
as_*()
sourcefn as_language(&self) -> Option<Language>
fn as_language(&self) -> Option<Language>
Convert a language object to a Language wrapper. Read more
sourcefn as_pairlist(&self) -> Option<Pairlist>
fn as_pairlist(&self) -> Option<Pairlist>
Convert a pair list object (LISTSXP) to a Pairlist wrapper. Read more
sourcefn as_expressions(&self) -> Option<Expressions>
fn as_expressions(&self) -> Option<Expressions>
Convert an expression object (EXPRSXP) to a Expr wrapper. Read more
sourcefn as_environment(&self) -> Option<Environment>
fn as_environment(&self) -> Option<Environment>
Convert an environment object (ENVSXP) to a Env wrapper. Read more
sourcefn as_function(&self) -> Option<Function>
fn as_function(&self) -> Option<Function>
Convert a function object (CLOSXP) to a Function wrapper. Read more
sourcefn as_promise(&self) -> Option<Promise>
fn as_promise(&self) -> Option<Promise>
Get a wrapper for a promise.
sourceimpl Debug for Environment
impl Debug for Environment
sourceimpl From<&'_ Environment> for Robj
impl From<&'_ Environment> for Robj
sourcefn from(val: &Environment) -> Self
fn from(val: &Environment) -> Self
Make an robj from a wrapper.
sourceimpl From<Environment> for Robj
impl From<Environment> for Robj
sourcefn from(val: Environment) -> Self
fn from(val: Environment) -> Self
Make an robj from a wrapper.
sourceimpl<'a> FromRobj<'a> for Environment
impl<'a> FromRobj<'a> for Environment
sourceimpl GetSexp for Environment
impl GetSexp for Environment
sourceimpl Length for Environment
impl Length for Environment
len() and is_empty()
sourceimpl Operators for Environment
impl Operators for Environment
dollar() etc.
sourcefn dollar<T>(&self, symbol: T) -> Result<Robj> where
T: AsRef<str>,
fn dollar<T>(&self, symbol: T) -> Result<Robj> where
T: AsRef<str>,
Do the equivalent of x$y Read more
sourcefn slice<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
fn slice<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
Do the equivalent of x[y]
Read more
sourcefn index<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
fn index<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
Do the equivalent of x[[y]]
Read more
sourcefn tilde<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
fn tilde<T>(&self, rhs: T) -> Result<Robj> where
T: Into<Robj>,
Do the equivalent of x ~ y Read more
sourceimpl PartialEq<Environment> for Environment
impl PartialEq<Environment> for Environment
sourcefn eq(&self, other: &Environment) -> bool
fn eq(&self, other: &Environment) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &Environment) -> bool
fn ne(&self, other: &Environment) -> bool
This method tests for !=
.
sourceimpl Rinternals for Environment
impl Rinternals for Environment
find_var() etc.
sourcefn is_logical(&self) -> bool
fn is_logical(&self) -> bool
Return true if this is a boolean (logical) vector
sourcefn is_complex(&self) -> bool
fn is_complex(&self) -> bool
Return true if this is a complex vector.
sourcefn is_expressions(&self) -> bool
fn is_expressions(&self) -> bool
Return true if this is an expression.
sourcefn is_environment(&self) -> bool
fn is_environment(&self) -> bool
Return true if this is an environment.
sourcefn is_promise(&self) -> bool
fn is_promise(&self) -> bool
Return true if this is an environment.
sourcefn is_external_pointer(&self) -> bool
fn is_external_pointer(&self) -> bool
Return true if this is an expression.
sourcefn get_current_srcref(val: i32) -> Robj
fn get_current_srcref(val: i32) -> Robj
Get the source ref.
sourcefn get_src_filename(&self) -> Robj
fn get_src_filename(&self) -> Robj
Get the source filename.
sourcefn as_character_vector(&self) -> Robj
fn as_character_vector(&self) -> Robj
Convert to a string vector.
sourcefn coerce_vector(&self, sexptype: u32) -> Robj
fn coerce_vector(&self, sexptype: u32) -> Robj
Convert to vectors of many kinds.
sourcefn pair_to_vector_list(&self) -> Robj
fn pair_to_vector_list(&self) -> Robj
Convert a pairlist (LISTSXP) to a vector list (VECSXP).
sourcefn vector_to_pair_list(&self) -> Robj
fn vector_to_pair_list(&self) -> Robj
Convert a vector list (VECSXP) to a pair list (LISTSXP)
sourcefn as_character_factor(&self) -> Robj
fn as_character_factor(&self) -> Robj
Convert a factor to a string vector.
sourcefn alloc_matrix(sexptype: SEXPTYPE, rows: i32, cols: i32) -> Robj
fn alloc_matrix(sexptype: SEXPTYPE, rows: i32, cols: i32) -> Robj
Allocate a matrix object.
sourcefn duplicate(&self) -> Robj
fn duplicate(&self) -> Robj
Do a deep copy of this object. Note that clone() only adds a reference. Read more
sourcefn find_function<K: TryInto<Symbol, Error = Error>>(
&self,
key: K
) -> Result<Robj>
fn find_function<K: TryInto<Symbol, Error = Error>>(
&self,
key: K
) -> Result<Robj>
Find a function in an environment ignoring other variables. Read more
sourcefn find_var<K: TryInto<Symbol, Error = Error>>(&self, key: K) -> Result<Robj>
fn find_var<K: TryInto<Symbol, Error = Error>>(&self, key: K) -> Result<Robj>
Find a variable in an environment. Read more
sourcefn eval_promise(&self) -> Result<Robj>
fn eval_promise(&self) -> Result<Robj>
If this object is a promise, evaluate it, otherwise return the object. Read more
sourcefn xlengthgets(&self, new_len: usize) -> Result<Robj>
fn xlengthgets(&self, new_len: usize) -> Result<Robj>
Copy a vector and resize it. See. https://github.com/hadley/r-internals/blob/master/vectors.md Read more
sourcefn alloc_vector(sexptype: u32, len: usize) -> Robj
fn alloc_vector(sexptype: u32, len: usize) -> Robj
Allocated an owned object of a certain type.
sourcefn conformable(a: &Robj, b: &Robj) -> bool
fn conformable(a: &Robj, b: &Robj) -> bool
Return true if two arrays have identical dims.
sourcefn is_function(&self) -> bool
fn is_function(&self) -> bool
Return true if this is a function or a primitive (CLOSXP, BUILTINSXP or SPECIALSXP)
sourcefn is_integer(&self) -> bool
fn is_integer(&self) -> bool
Return true if this is an integer vector (INTSXP) but not a factor.
sourcefn is_language(&self) -> bool
fn is_language(&self) -> bool
Return true if this is a language object (LANGSXP).
sourcefn is_pairlist(&self) -> bool
fn is_pairlist(&self) -> bool
Return true if this is NILSXP or LISTSXP.
sourcefn is_primitive(&self) -> bool
fn is_primitive(&self) -> bool
Return true if this is a primitive function BUILTINSXP, SPECIALSXP.
sourcefn is_user_binop(&self) -> bool
fn is_user_binop(&self) -> bool
Return true if this is a user defined binop.
sourcefn is_valid_string(&self) -> bool
fn is_valid_string(&self) -> bool
Return true if this is a valid string.
sourcefn is_valid_string_f(&self) -> bool
fn is_valid_string_f(&self) -> bool
Return true if this is a valid string.
sourcefn is_vector_atomic(&self) -> bool
fn is_vector_atomic(&self) -> bool
Return true if this is an atomic vector.
sourcefn is_vector_list(&self) -> bool
fn is_vector_list(&self) -> bool
Return true if this is a vector list.
sourcefn is_vectorizable(&self) -> bool
fn is_vectorizable(&self) -> bool
Return true if this is can be made into a vector.
fn is_missing_arg(&self) -> bool
fn is_unbound_value(&self) -> bool
fn is_package_env(&self) -> bool
fn package_env_name(&self) -> Robj
fn is_namespace_env(&self) -> bool
fn namespace_env_spec(&self) -> Robj
sourcefn is_altinteger(&self) -> bool
fn is_altinteger(&self) -> bool
Returns true
if this is an integer ALTREP object.
sourcefn is_altreal(&self) -> bool
fn is_altreal(&self) -> bool
Returns true
if this is an real ALTREP object.
sourcefn is_altlogical(&self) -> bool
fn is_altlogical(&self) -> bool
Returns true
if this is an logical ALTREP object.
sourcefn is_altstring(&self) -> bool
fn is_altstring(&self) -> bool
Returns true
if this is an integer ALTREP object.
sourceimpl Serialize for Environment
impl Serialize for Environment
sourceimpl Slices for Environment
impl Slices for Environment
as_typed_slice_raw() etc.
sourceimpl TryFrom<&'_ Robj> for Environment
impl TryFrom<&'_ Robj> for Environment
sourceimpl TryFrom<Robj> for Environment
impl TryFrom<Robj> for Environment
sourceimpl Types for Environment
impl Types for Environment
rtype() and rany()
impl StructuralPartialEq for Environment
Auto Trait Implementations
impl RefUnwindSafe for Environment
impl !Send for Environment
impl !Sync for Environment
impl Unpin for Environment
impl UnwindSafe for Environment
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more