Get the list of declared dependencies of a module.

get_dependencies(name = .Last.name, load = FALSE)

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?

Value

A list of dependencies.

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

#> [2017-06-21T21:58:21 UTC] Resetting modulr state ... OK
define("foo", NULL, function() "foo")
#> [2017-06-21T21:58:21 UTC] Defining 'foo' ... OK
define("bar", list(foo = "foo"), function(foo) paste0(foo, "bar"))
#> [2017-06-21T21:58:21 UTC] Defining 'bar' ... OK
define("bar/mock", get_dependencies("bar"), function(foo) paste0(foo, "baz"))
#> [2017-06-21T21:58:21 UTC] Defining 'bar/mock' ... OK
make("bar/mock")
#> [2017-06-21T21:58:21 UTC] Making 'bar/mock' ... #> [2017-06-21T21:58:21 UTC] * Visiting and defining dependencies ... #> [2017-06-21T21:58:21 UTC] * Constructing dependency graph ... OK #> [2017-06-21T21:58:21 UTC] * Evaluating #1/1 (layer #1/1): 'foo' ... #> [2017-06-21T21:58:21 UTC] DONE ('bar/mock' in 0.036 secs)
#> [1] "foobaz"
#> [2017-06-21T21:58:21 UTC] Resetting modulr state ... OK
tmp_dir <- tempfile("modulr_") dir.create(tmp_dir) cat('define("foo", NULL, function() "Hello")', file = file.path(tmp_dir, "foo.R")) cat('define("bar", list(foo = "foo"), function() paste(foo, "World!"))', file = file.path(tmp_dir, "bar.R")) root_config$set(tmp_dir) ## Not run: get_dependencies("bar", load = FALSE) get_dependencies("bar", load = TRUE)
#> [2017-06-21T21:58:21 UTC] Defining 'bar' ... OK
#> $foo #> [1] "foo" #>
unlink(tmp_dir, recursive = TRUE)