amodule: Define Augmented and Parameterized Modules

Description Usage Arguments Examples

View source: R/amodule.R

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

1
2
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

1
2
3
4
5
6
7
Constructor <- function(dependency) {
  amodule({
    fun <- function(...) dependency(...)
  })
}
instance <- Constructor(identity)
instance$fun(1)

wahani/module documentation built on Nov. 16, 2018, midnight