pub struct Quoted<'a> {
expr: SEXP,
env: SEXP,
_arg: PhantomData<&'a SEXP>,
_not_send: PhantomData<*const ()>,
}Expand description
An argument passed unevaluated: its expression and the environment it was
written in, as base R’s substitute(x) and parent.frame() give them.
Take it as a #[miniextendr] parameter. The generated wrapper keeps the
parameter as an R formal and passes
if (missing(x)) quote(expr=) else list(substitute(x), parent.frame()),
which never forces the argument. See the module docs.
use miniextendr_api::{miniextendr, Quoted, SEXP};
#[miniextendr]
pub fn column_name(col: Quoted) -> Option<String> {
col.as_name().map(str::to_owned) // column_name(TIME), column_name("TIME")
}
#[miniextendr]
pub fn evaluate(expr: Quoted) -> SEXP {
expr.eval() // eval(expr, env)
}parent.frame() is the environment of the function that called the
wrapper, which is where the expression was written when the user calls the
wrapper directly or through UseMethod(). A wrapper reached through a
function that forwards its own argument (g <- function(y) f(y)) receives
y and g’s frame, as subset() does. To resolve forwarding, {{ x }}
and !!x, take a Quosure.
Fields§
§expr: SEXP§env: SEXP§_arg: PhantomData<&'a SEXP>Borrows the .Call() argument that roots expr and env.
_not_send: PhantomData<*const ()>R objects stay on R’s main thread.
Implementations§
Source§impl<'a> Quoted<'a>
impl<'a> Quoted<'a>
Source#[doc(hidden)]pub unsafe fn from_wrapper_arg(arg: &'a SEXP) -> Option<Self>
#[doc(hidden)]pub unsafe fn from_wrapper_arg(arg: &'a SEXP) -> Option<Self>
Source#[doc(hidden)]pub unsafe fn missing_from_wrapper_arg(arg: &'a SEXP) -> Missing<Self>
#[doc(hidden)]pub unsafe fn missing_from_wrapper_arg(arg: &'a SEXP) -> Missing<Self>
Sourcepub fn expr(&self) -> SEXP
pub fn expr(&self) -> SEXP
The expression as written: a symbol, a call, or a constant
(substitute(x)).
Sourcepub fn as_name(&self) -> Option<&'a str>
pub fn as_name(&self) -> Option<&'a str>
The name the argument stands for: TIME and "TIME" both give
"TIME". None for any other expression (a call, a number, NA).
Sourcepub fn eval(&self) -> SEXP
pub fn eval(&self) -> SEXP
Evaluate the expression in its environment, eval(expr, env), keeping
the caller’s condition handlers
(eval_with_handlers).
The value is unprotected: protect it before the next allocation.
Sourcepub fn eval_in(&self, data: SEXP) -> SEXP
pub fn eval_in(&self, data: SEXP) -> SEXP
Evaluate the expression with data as a data mask, like
eval(expr, data, env): the elements of a list or the columns of a
data frame are visible by name, ahead of the expression’s environment.
The first of two elements with one name wins, and unnamed elements are
not visible. An environment is used as is (env is not consulted),
and NULL evaluates in the expression’s environment.
The value is unprotected: protect it before the next allocation.
§Panics
When data is not a list, a data frame, an environment or NULL.
Sourcepub fn try_eval_in(&self, data: SEXP) -> Result<SEXP, REvalError>
pub fn try_eval_in(&self, data: SEXP) -> Result<SEXP, REvalError>
eval_in with an R error returned as Err, as
try_eval_with_handlers
returns it: the caller’s handlers still see the expression’s warnings
and messages. The mask and the rules for data are eval_in’s.
A subset() method can explain a column that doesn’t exist and leave
every other error as R raised it
(REvalError::reraise):
let keep = match subset.try_eval_in(table) {
Ok(keep) => keep,
// `unknown_column` compares the expression's names with the table's.
Err(e) if unknown_column(&subset, table) => {
rust_error!(class = "pkg_unknown_column", "{e}; the columns are ...")
}
// SAFETY: inside the `#[miniextendr]` call.
Err(e) => unsafe { e.reraise() },
};The value is unprotected: protect it before the next allocation.
§Panics
When data is not a list, a data frame, an environment or NULL.
Auto Trait Implementations§
impl<'a> !Send for Quoted<'a>
impl<'a> !Sync for Quoted<'a>
impl<'a> Freeze for Quoted<'a>
impl<'a> RefUnwindSafe for Quoted<'a>
impl<'a> Unpin for Quoted<'a>
impl<'a> UnsafeUnpin for Quoted<'a>
impl<'a> UnwindSafe for Quoted<'a>
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: 16 bytes