Access module helper functions.

Format

A list of functions.

post_evaluation_hook(expr, add = FALSE)
message_info(...)
message_warn(...)
message_stop(...)
    ## Deprecated ##
get_module_name()
get_module_options()
get_filename()
get_dirname()

Details

The purpose of the special module 'modulr' is to give access to useful helper functions related to the module into which it is injected.

<code>post_evaluation_hook(expr, add = FALSE)</code>

Records the expression given as its argument as needing to be executed when the current module evaluation exits (either naturally or as the result of an error). If no expression is provided, i.e., the call is `post_evaluation_hook()`, then the current expression is removed. If `add` is `TRUE`, `expr` is added after any previously set expressions; otherwise (the default) `expr` will overwrite any previously set expressions.

<code>message_info(...), message_warn(...), and message_stop(...)</code>

Outputs an informative, warning, or critical and stopping message, prefixed with a timestamp and the module name. Such messages are particularily useful in modules involved in long chains of dependencies and workflows.

<code>get_module_name()</code>

Returns a string (character vector of lenght one) containing the module name. See define. Deprecated and kept for backward compatibility.

<code>get_module_version()</code>

Returns numeric version of the module. Deprecated and kept for backward compatibility.

<code>get_module_options()</code>

Returns a list containing the module options. See module_options. Deprecated and kept for backward compatibility.

<code>get_filename(absolute = TRUE)</code>

Returns a string (character vector of lenght one) containing the module (absolute) filename. Deprecated and kept for backward compatibility.

<code>get_dirname(absolute = TRUE)</code>

Returns a string (character vector of lenght one) containing the module (absolute) dirname. Deprecated and kept for backward compatibility.

See also

define, module_options, and reset.

Examples

reset() define("foo", list(modulr = "modulr"), function(modulr) { list( info = function() modulr$message_info("Module name: ", .__name__), warn = function() modulr$message_warn("Module name: ", .__name__), stop = function() modulr$message_stop("Module name: ", .__name__) ) })
#> [2018-12-02T17:14:07 CET] Defining 'foo' ... OK
foo <- make()
#> [2018-12-02T17:14:07 CET] Making 'foo' ... #> [2018-12-02T17:14:07 CET] * Visiting and defining dependencies ... #> [2018-12-02T17:14:07 CET] * Constructing dependency graph ... OK #> [2018-12-02T17:14:07 CET] * Evaluating #1/1 (layer #1/1): 'modulr#0.1.7.9209' ... #> [2018-12-02T17:14:07 CET] DONE ('foo' in 0.054 secs)
foo$info()
#> [2018-12-02T17:14:07 CET foo] Module name: foo
foo$warn()
#> Warning: [2018-12-02T17:14:07 CET foo] Module name: foo
#> [2018-12-02T17:14:07 CET] Resetting modulr state ... OK
tmp_dir <- tempfile("modulr_") dir.create(tmp_dir) tmp_file <- file.path(tmp_dir, "foo.R") cat( 'define("foo", list(modulr = "modulr"), function(modulr) { modulr$message_info("Module file name: ", .__file__) modulr$message_info("Module file path: ", .__path__) })', sep = "\n", file = tmp_file) root_config$set(tmp_dir) make("foo")
#> [2018-12-02T17:14:07 CET] Making 'foo' ... #> [2018-12-02T17:14:07 CET] * Visiting and defining dependencies ... #> [2018-12-02T17:14:07 CET] ** Defining 'foo' ... OK #> [2018-12-02T17:14:07 CET] * Constructing dependency graph ... OK #> [2018-12-02T17:14:07 CET] * Evaluating #1/1 (layer #1/1): 'modulr#0.1.7.9209' ...
#> [2018-12-02T17:14:07 CET foo] * Module file name: /tmp/RtmpxG72Ok/modulr_7f3641b3a2e4/foo.R
#> [2018-12-02T17:14:07 CET foo] * Module file path: /tmp/RtmpxG72Ok/modulr_7f3641b3a2e4
#> [2018-12-02T17:14:07 CET] DONE ('foo' in 0.068 secs)
unlink(tmp_dir, recursive = TRUE) ## Not run: foo$stop() reset()
#> [2018-12-02T17:14:07 CET] Resetting modulr state ... OK
"foo" %requires% list(modulr = "modulr") %provides% { modulr$post_evaluation_hook(touch("foo")) message("Hello, I am a ", sQuote("no-scoped"), " module.") }
#> [2018-12-02T17:14:07 CET] Defining 'foo' ... OK
make("foo")
#> [2018-12-02T17:14:07 CET] Making 'foo' ... #> [2018-12-02T17:14:07 CET] * Visiting and defining dependencies ... #> [2018-12-02T17:14:07 CET] * Constructing dependency graph ... OK #> [2018-12-02T17:14:07 CET] * Evaluating #1/1 (layer #1/1): 'modulr#0.1.7.9209' ...
#> Hello, I am a ‘no-scoped’ module.
#> [2018-12-02T17:14:07 CET] * Touching 'foo' ... OK #> [2018-12-02T17:14:07 CET] DONE ('foo' in 0.062 secs)
make("foo")
#> [2018-12-02T17:14:07 CET] Making 'foo' ... #> [2018-12-02T17:14:07 CET] * Visiting and defining dependencies ... #> [2018-12-02T17:14:07 CET] * Constructing dependency graph ... OK
#> Hello, I am a ‘no-scoped’ module.
#> [2018-12-02T17:14:07 CET] * Touching 'foo' ... OK #> [2018-12-02T17:14:07 CET] DONE ('foo' in 0.059 secs)
#> [2018-12-02T17:14:07 CET] Resetting modulr state ... OK
"foo" %requires% list(modulr = "modulr") %provides% { modulr$post_evaluation_hook(undefine("foo")) message("Hello, I am an ", sQuote("ephemeral"), " module.") }
#> [2018-12-02T17:14:07 CET] Defining 'foo' ... OK
make("foo")
#> [2018-12-02T17:14:07 CET] Making 'foo' ... #> [2018-12-02T17:14:07 CET] * Visiting and defining dependencies ... #> [2018-12-02T17:14:07 CET] * Constructing dependency graph ... OK #> [2018-12-02T17:14:07 CET] * Evaluating #1/1 (layer #1/1): 'modulr#0.1.7.9209' ...
#> Hello, I am an ‘ephemeral’ module.
#> [2018-12-02T17:14:07 CET] * Undefining 'foo' ... OK #> [2018-12-02T17:14:07 CET] DONE ('foo' in 0.053 secs)
## Not run: make("foo")