Load or reload all modules which are defined in the named directory.

load_all_modules(path = c("lib", "libs", "module", "modules", "."),
  pattern = "[^_]\\.[rR][(?:md)|(?:nw)]?$", full.names = TRUE,
  recursive = TRUE, ...)

Arguments

path

a character vector of full path names; the default corresponds to the working directory, getwd(). Tilde expansion (see path.expand) is performed. Missing values will be ignored.

pattern

an optional regular expression. Only file names which match the regular expression will be returned.

full.names

a logical value. If TRUE, the directory path is prepended to the file names to give a relative file path. If FALSE, the file names (rather than paths) are returned.

recursive

logical. Should the listing recurse into directories?

...

Further arguments to be passed to base::list.files.

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

load_module, make_all, and reset.

Examples

#> [2017-06-21T21:58:26 UTC] 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() print("Hello World!"))', file = tmp_file) tmp_file <- file.path(tmp_dir, "bar.R") cat('define("bar", NULL, function() print("hELLO wORLD?"))', file = tmp_file) load_all_modules(tmp_dir)
#> [2017-06-21T21:58:26 UTC] Defining 'bar' ... OK #> [2017-06-21T21:58:26 UTC] Defining 'foo' ... OK
#> [2017-06-21T21:58:26 UTC] Making 'bar' ... #> [2017-06-21T21:58:26 UTC] * Visiting and defining dependencies ... #> [2017-06-21T21:58:26 UTC] * Constructing dependency graph ... OK #> [1] "hELLO wORLD?" #> [2017-06-21T21:58:26 UTC] DONE ('bar' in 0.013 secs) #> [2017-06-21T21:58:26 UTC] Making 'foo' ... #> [2017-06-21T21:58:26 UTC] * Visiting and defining dependencies ... #> [2017-06-21T21:58:26 UTC] * Constructing dependency graph ... OK #> [1] "Hello World!" #> [2017-06-21T21:58:26 UTC] DONE ('foo' in 0.013 secs)
unlink(tmp_dir, recursive = TRUE)