Function extendr_api::functions::local_var

source ·
pub fn local_var<K: Into<Robj>>(key: K) -> Result<Robj>
Expand description

Get a local variable from current_env() and ancestors.

If the result is a promise, evaulate the promise. The result will come from the calling environment of an R function which will enable you to use variables from the caller.

See also var!.

Note that outside of R, current_env() will be base_env() and cannot be modified.

use extendr_api::prelude::*;
test! {
   current_env().set_local(sym!(my_var), 1);
   assert_eq!(local_var(sym!(my_var))?, r!(1));
}