amodule {modules}R Documentation

Define Augmented and Parameterized Modules

Description

amodule is a wrapper around module and changes the default environment to which the module connects. In contrast to module the top enclosing environment here is always baseenv. The second important difference is that the environment in which a module is created has meaning: all objects are made available to the module scope. This is what is meant by augmented or parameterized. Best practice for the use of this behavior is to return these modules from functions.

Usage

amodule(expr = {
}, envir = parent.frame(), enclos = baseenv(), class = NULL)

Arguments

expr

(expression) a module declaration, same as module

envir

(environment) environment used to detect 'parameters'

enclos

(environment) the top enclosing environment of the module scope.

class

(character) the module can have a class attribute for consistency. If you rely on S3 dispatch, e.g. to override the default print method, you should set this value explicitly.

Examples

Constructor <- function(dependency) {
  amodule({
    fun <- function(...) dependency(...)
  })
}
instance <- Constructor(identity)
instance$fun(1)


[Package modules version 0.13.0 Index]