Load or reload a module which is defined in an R, R Markdown or R Sweave file stored on disk.

load_module(name = .Last.name)

Arguments

name

A string (character vector of lenght one).

A module name can contain letters, figures and some special characters, namely _, -, and /. The latter is a namespace separator.

Names containing /mock/, /mocks/, /test/, /tests/, /example/, or /examples/ have a special meaning related to code testing and examples.

The name "modulr" corresponds to a special module and is therefore reserved.

Value

The absolute file name of the loaded module.

Details

As described in define under Implicit Definition, the module name is resolved into a file location by applying the rules accessed by root_config, paths_config, and maps_config. R Markdown and R Sweave files are accordingly tangled into R code, which is in turn evaluated.

Warning

It is considered a very bad practice to define, touch, undefine, load, make, reset, or perform any other operation from within a module definition that may alterate the internal state of modulr.

See also

.Last.name, make, maps_config, paths_config, and reset.

Examples

#> [2018-12-02T17:14:05 CET] Resetting modulr state ... OK
tmp_dir <- tempfile("modulr_") dir.create(tmp_dir) tmp_file <- file.path(tmp_dir, "foo.R") cat('define("foo", NULL, function() "Hello World!")', file = tmp_file) root_config$set(tmp_dir) load_module("foo")
#> [2018-12-02T17:14:05 CET] Defining 'foo' ... OK
#> foo #> "/tmp/RtmpxG72Ok/modulr_7f365e6130b7/foo.R"
#> [2018-12-02T17:14:05 CET] Making 'foo' ... #> [2018-12-02T17:14:05 CET] * Visiting and defining dependencies ... #> [2018-12-02T17:14:05 CET] * Constructing dependency graph ... OK #> [2018-12-02T17:14:05 CET] DONE ('foo' in 0.039 secs)
#> [1] "Hello World!"
unlink(tmp_dir, recursive = TRUE) load_module("foo")
#> foo #> NA