makeClosure: Turn a function into a closure with some non-local variables

View source: R/runTime.R

makeClosureR Documentation

Turn a function into a closure with some non-local variables

Description

This function takes a function and assigns it an environment and then puts the specified variables into that environment so that they are available when the function is called and not in the global search path.

This function is used when we dynamically generate code to interface to C routines.

Usage

makeClosure(fun, ..., .els = list(...), env = new.env())

Arguments

fun

the function whose environment is to be changed

...

name = value pairs giving the variable names and their values that are to be stored in the function's environment.

.els

a named list of values, providing an alternative way to specify the variables to be stored in the environment.

env

the environment to use as the function's environment

Value

The modified function whose environment is env.

Author(s)

Duncan Temple Lang

See Also

The package RGCCTUFFI (https://github.com/omegahat/RGCCTUFFI) has a related createRFunc function.

Examples

  f = function(x, y)
          x + y + z

  f = makeClosure(f, z = 2, w = "not used")
  f(1, 3)

omegahat/Rffi documentation built on Nov. 29, 2023, 12:48 a.m.