Find a module, in the context of a module scope, if any.

find_module(name, scope_name = NULL, absolute = TRUE, extensions = c(".R",
  ".r", ".Rmd", ".rmd", ".Rnw", ".rnw"))

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.

scope_name

A module name to use as scope (see define, maps_config, and examples).

absolute

A flag. Should the returned path be absolute? (see define, root_config, and examples)

extensions

A character vector. File extensions to consider.

Value

A list containing informations relative to the module: name, version, in-memory or on-disk storage, and file path (absolute or relative).

See also

define, find_path, maps_config, reset, and root_config,

Examples

#> [2017-06-21T21:58:20 UTC] Resetting modulr state ... OK
define("foo", NULL, function() "Hello World!")
#> [2017-06-21T21:58:20 UTC] Defining 'foo' ... OK
find_module("foo")
#> $name #> [1] "foo" #> #> $version #> [1] <NA> #> #> $storage #> [1] "in-memory" #> #> $filepath #> [1] NA #>
#> [2017-06-21T21:58:20 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() "Hello World!")', file = tmp_file) root_config$set(tmp_dir) set_verbosity(1L) find_module("foo")
#> $name #> [1] "foo" #> #> $version #> [1] <NA> #> #> $storage #> [1] "on-disk" #> #> $filepath #> [1] "/tmp/Rtmp4WPoWj/modulr_1950210c4257/foo.R" #>
unlink(tmp_dir, recursive = TRUE) reset() tmp_dir <- tempfile("modulr_") dir.create(file.path(tmp_dir, 'foo'), recursive = TRUE) dir.create(file.path(tmp_dir, 'vendor'), recursive = TRUE) cat(paste0('define("bar", list(great_module = "vendor/great_module"), ', 'function() great_module)'), file = file.path(tmp_dir, "foo", "bar.R")) cat('define("great_module", NULL, function() "Great Module")', file = file.path(tmp_dir, "vendor", "great_module.R")) cat('define("great_module", NULL, function() "Old Great Module")', file = file.path(tmp_dir, "vendor", "old_great_module.R")) root_config$set(tmp_dir) set_verbosity(1L) find_module("vendor/great_module") maps_config$set("foo/bar" = list("vendor/great_module" = "vendor/old_great_module")) find_module("vendor/great_module", "foo/bar") unlink(tmp_dir, recursive = TRUE)