Description Usage Arguments Details Value Warning See Also Examples
Create an new injector, set and get the current injector, and get the default injector.
1 2 3 4 5 6 7 8 9 |
injector |
An injector returned by |
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.
Every function returns an injector (R environment).
Setting an injector from within a module is not allowed and results in an error.
.SharedEnv
, define
,
list_modules
, make
, and reset
.
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.