get_provider: Get the Provider of a Module.

Description Usage Arguments Details Value Warning See Also Examples

View source: R/define.R

Description

Get the provider function of a module.

Usage

1

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.

load

A flag. Should an undefined module be implicitely loaded?

Details

For testing purposes, it is often useful for mocks to be able to refer to the provider of a module.

Value

A function identical to the provider function of the module.

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

define, make, reset, and root_config.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
reset()
define("foo", NULL, function() "foo")
define("bar", list(foo = "foo"), function(foo) paste0(foo, "bar"))
define("foo/mock", NULL, function() "foooooo")
define("bar/mock", list(foo = "foo/mock"), get_provider("bar"))
make("bar/mock")

reset()
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)
## Not run: get_provider("foo", load = FALSE)
get_provider("foo", load = TRUE)
unlink(tmp_dir, recursive = TRUE)

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