modulr-module: Special Module "modulr"

Description Format Details post_evaluation_hook(expr, add = FALSE) message_info(...), message_warn(...), and message_stop(...) get_module_name() get_module_version() get_module_options() get_filename(absolute = TRUE) get_dirname(absolute = TRUE) See Also Examples

Description

Access module helper functions.

Format

A list of functions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

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.

post_evaluation_hook(expr, add = FALSE)

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.

message_info(...), message_warn(...), and message_stop(...)

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.

get_module_name()

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

get_module_version()

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

get_module_options()

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

get_filename(absolute = TRUE)

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

get_dirname(absolute = TRUE)

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

 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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__)
  )
})
foo <- make()
foo$info()
foo$warn()

reset()
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")
unlink(tmp_dir, recursive = TRUE)

## Not run: foo$stop()

reset()
"foo" %requires% list(modulr = "modulr") %provides% {
  modulr$post_evaluation_hook(touch("foo"))
  message("Hello, I am a ", sQuote("no-scoped"), " module.")
}
make("foo")
make("foo")

reset()
"foo" %requires% list(modulr = "modulr") %provides% {
  modulr$post_evaluation_hook(undefine("foo"))
  message("Hello, I am an ", sQuote("ephemeral"), " module.")
}
make("foo")
## Not run: make("foo")

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