expose: Expose module contents

View source: R/expose.R

exposeR Documentation

Expose module contents

Description

Use expose to copy the exported member of a module to the calling environment. This is useful for a simple reexport of member functions and generally for object composition.

Usage

expose(module, ..., reInit = TRUE, where = parent.frame())

Arguments

module

(character | module) a module as file or folder name or a list representing a module.

...

(character, or unquoted expression) elements to be exposed. Defaults to all.

reInit

(logical) whether to re-initialize module. This is only relevant if a module has state which can be changed. This argument is passed to as.module.

where

(environment) typically the calling environment. Should only be relevant for testing.

Details

You call this function for its side effects. It is a variation of use where instead of returning a module as return value, the elements are copied to the calling environment.

Examples

m1 <- module({
  foo <- function() "foo"
})
m2 <- module({
  bar <- function() "bar"
})
# Now we create a module with 'foo' and 'bar' as member functions.
m3 <- module({
  expose(m1)
  expose(m2)
})
m3$foo()
m3$bar()

modules documentation built on May 29, 2024, 2 a.m.