crate: Isolate a Function from its Environment

View source: R/crate.R

crateR Documentation

Isolate a Function from its Environment

Description

Put a function in a "lean" environment that does not carry unnecessary baggage with it (e.g. references to datasets).

Usage

crate(.fn, ..., .parent = topenv())

Arguments

.fn

(⁠function()⁠)
function to crate

...

(any)
The objects, which should be visible inside .fn.

.parent

(environment)
Parent environment to look up names. Default to topenv().

Examples

meta_f = function(z) {
  x = 1
  y = 2
  crate(function() {
    c(x, y, z)
  }, x)
}
x = 100
y = 200
z = 300
f = meta_f(1)
f()

mlr3misc documentation built on Sept. 20, 2023, 5:06 p.m.