injector: Create, Set, and Get Injectors (Modulr Internal States).

Description Usage Arguments Details Value Warning See Also Examples

Description

Create an new injector, set and get the current injector, and get the default injector.

Usage

1
2
3
4
5
6
7
8
9

Arguments

injector

An injector returned by new_injector.

Details

An injector essentially carries an internal modulr state. Technically, it is is an R environment containing every piece of information needed by modulr to reflect the module definitions, the dependencies between them, the configurations, and all the associated metadata. As a PORO (Plain Old R Object), an injector can be stored to disk with the session data, or shared between Alice and Bob, for instance.

When the modulr package is loaded, a default injector is created. This injector is returned by the get_default_injector function.

Value

Every function returns an injector (R environment).

Warning

Setting an injector from within a module is not allowed and results in an error.

See Also

.SharedEnv, define, list_modules, make, and reset.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
reset()
define("foo", NULL, function() NULL)
injector <- new_injector()
previous_injector <- set_injector(injector)
define("bar", NULL, function() NULL)
lsmod()
set_injector(previous_injector)
lsmod()

## Not run: 
.Last <- function() {
 # Bind the current injector (internal modulr state) to the environment.
 injector <- get_injector()
}
quit(save = "yes")
## End(Not run)

reset()
define("foo", NULL, function() "Hi Bob!")
## Alice saves its injector and sends it to ...
saveRDS(get_injector(), file = "injector.R")
## ... Bob who restores it.
injector <- readRDS("injector.R")
set_injector(injector)
make("foo")

openscienceunil/modulr documentation built on May 3, 2019, 5:49 p.m.