pub struct REnv {
sexp: SEXP,
}Expand description
Handle to a well-known R environment.
Provides access to R’s standard environments without raw FFI calls.
Fields§
§sexp: SEXPImplementations§
Source§impl REnv
impl REnv
Sourcepub fn base_namespace() -> Self
pub fn base_namespace() -> Self
The base namespace (SEXP::base_namespace()).
Unlike base() which is the base environment (exported
functions visible to users), this is the base namespace (includes
internal helpers). Rarely needed — prefer base() unless
you specifically need unexported base internals.
§Safety
Must be called from the R main thread.
Sourcepub unsafe fn package_namespace(name: &str) -> Result<Self, REvalError>
pub unsafe fn package_namespace(name: &str) -> Result<Self, REvalError>
A package’s namespace environment.
Finds the namespace for a loaded package. Use this to evaluate functions
that live in a specific package (e.g., slot() from methods).
This is a safe wrapper around getNamespace(name), evaluated through
RCall::eval, so a missing namespace returns Err instead of
longjmping through Rust frames.
§Safety
Must be called from the R main thread.
§Errors
R’s error when the namespace cannot be loaded (a
packageNotFoundError for a package that is not installed).
Sourcepub unsafe fn caller() -> Self
pub unsafe fn caller() -> Self
The current execution environment.
Returns the environment of the innermost active closure on R’s call stack, or the global environment if no closure is active.
Useful when you need to evaluate an expression in the caller’s context rather than a fixed well-known environment.
§Safety
Must be called from the R main thread.
Sourcepub unsafe fn get(&self, name: &str) -> Option<SEXP>
pub unsafe fn get(&self, name: &str) -> Option<SEXP>
The value bound to name in this environment’s own frame, as R’s
get0(name, envir = env, inherits = FALSE) reads it, or None when
the frame has no such binding. The enclosing environments are not
searched; get_inherits searches them.
A binding to NULL is Some of NULL. Reading a binding does what
get0() does:
- A promise is forced, once, and its value is kept in the promise. A
function in a lazy-loaded namespace, a
delayedAssign()and an argument of an R function are promises. So this is not a check for whether a name is bound without running anything. - An active binding (
makeActiveBinding()) calls its function. - A binding to the missing argument raises R’s error.
R 4.5 and later read the binding with R_getVarEx; R 4.4 evaluates
base::get0(). Both give the same results. An R error raised while
reading, such as a promise or an active binding that fails, unwinds the
Rust frames up to the miniextendr boundary, which hands it back to R,
as under eval_with_handlers.
§Safety
R’s main thread, inside a miniextendr boundary: a #[miniextendr]
function body, a with_r_unwind_protect
closure, an ALTREP callback with the r_unwind or rust_unwind guard,
a connection callback, a with_r_thread
closure.
§Returns
The value, unprotected. A plain binding, or a forced promise,
keeps it reachable while the name stays bound to it. An active
binding’s value is new and held by nothing. Protect the value
(OwnedProtect, Preserved) before the next
allocation unless the binding is known to be a plain value, and before
anything that may rebind the name: R code you evaluate, or
define.
§Panics
Panics if name contains a null byte.
Sourcepub unsafe fn get_inherits(&self, name: &str) -> Option<SEXP>
pub unsafe fn get_inherits(&self, name: &str) -> Option<SEXP>
The value bound to name in this environment or the nearest enclosing
environment that binds it, as R’s get0(name, envir = env, inherits = TRUE) reads it, or None when none does.
Bindings are read as get reads them: a promise is
forced, an active binding is called. The search stops at the first
binding of name, whatever its value.
§Safety
As get.
§Returns
The value, unprotected, as get returns it.
§Panics
Panics if name contains a null byte.
Sourcepub unsafe fn define(&self, name: &str, value: SEXP)
pub unsafe fn define(&self, name: &str, value: SEXP)
Bind name to value in this environment’s own frame, as
assign(name, value, envir = env) does: a binding of name in the
frame is replaced, and the enclosing environments are not touched.
R raises its error, which unwinds as under get, when
the binding cannot be made: the empty environment, a locked
environment that lacks the binding (a package namespace, once the
package is loaded), or a locked binding. Assigning to an active binding
calls its function with value.
§Safety
As get. value is a valid SEXP; it needs no root of
its own, and the binding keeps it reachable afterwards.
§Panics
Panics if name contains a null byte.
Sourcepub(crate) unsafe fn define_symbol(&self, symbol: SEXP, value: SEXP)
pub(crate) unsafe fn define_symbol(&self, symbol: SEXP, value: SEXP)
Auto Trait Implementations§
impl Freeze for REnv
impl RefUnwindSafe for REnv
impl Send for REnv
impl Sync for REnv
impl Unpin for REnv
impl UnsafeUnpin for REnv
impl UnwindSafe for REnv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes