find_path: Find the Path of a Module.

Description Usage Arguments Value See Also Examples

View source: R/routes.R

Description

Find the path of a module, in the context of a module scope, if any. The returned path can be absolute or relative to a root directory.

Usage

1
find_path(name, scope_name = NULL, ...)

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).

...

Further arguments to be passed to find_module.

Value

A string containing the path (relative or absolute) of the module.

See Also

define, find_module, maps_config, reset, and root_config,

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
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)
set_verbosity(1L)
find_path("foo")
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_path("vendor/great_module")
maps_config$set("foo/bar" = list("vendor/great_module" =
                                 "vendor/old_great_module"))
find_path("vendor/great_module", "foo/bar")
unlink(tmp_dir, recursive = TRUE)

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