Get the digest (a xxHash64 hash of the dependencies and provider) of a module.

get_digest(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 string containing the digest of the module.

Details

A digest is useful for comparing two modules. For instance, in order to know if a module definition has changed, a digest of the newly presented module is computed and compared to the existing one. When a module is imported from an URL, it is also possible to specify a digest. The imported module is then rejected if its digest differs from the expected value.

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 and root_config.

Examples

#> [2017-06-21T21:58:21 UTC] Resetting modulr state ... OK
define("foo", NULL, function() NULL)
#> [2017-06-21T21:58:21 UTC] Defining 'foo' ... OK
get_digest("foo")
#> [1] "1d0c1bd9ed63b01f"
#> [2017-06-21T21:58:21 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() NULL)', file = tmp_file) root_config$set(tmp_dir) ## Not run: get_digest("foo", load = FALSE) get_digest("foo", load = TRUE)
#> [2017-06-21T21:58:21 UTC] Defining 'foo' ... OK
#> [1] "1d0c1bd9ed63b01f"
unlink(tmp_dir, recursive = TRUE)