Import or re-import a module which is defined in an R, R Markdown or R Sweave script at a given URL using the HTTP(S) protocol.

import_module(name, url, ..., digest = NULL, force = 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.

url

A string (character vector of length one). The URL must use the HTTP(S) protocol.

...

Further arguments passed to httr::GET.

digest

A string (character vector of length one). See get_digest.

force

A flag. Should an already defined module be re-imported?

Value

The result of the evaluation of the imported script.

Details

R Markdown and R Sweave files are accordingly tangled into R code, which is in turn evaluated.

The imported module is rejected if

  • its name differs from the name argument,

  • its digest differs from the digest argument.

In such a case, the internal state of modulr is rolled back.

Syntactic Sugars

name %imports% url

name %digests% digest %imports% url

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

httr::GET, get_digest, list_modules, make, and make_tests.

Examples

not_run({ reset() # https://gist.github.com/aclemen1/3fcc508cb40ddac6c1e3 "modulr/vault" %imports% "https://gist.github.com/aclemen1/3fcc508cb40ddac6c1e3" list_modules() reset() # equivalently "modulr/vault" %imports% "3fcc508cb40ddac6c1e3" make("modulr/vault/example") make_tests() }) not_run({ reset() # https://gist.github.com/aclemen1/3fcc508cb40ddac6c1e3 "modulr/vault_with_a_typo" %imports% "3fcc508cb40ddac6c1e3" list_modules() }) not_run({ reset() # https://gist.github.com/aclemen1/3fcc508cb40ddac6c1e3 "modulr/vault" %digests% "with a wrong digest" %imports% "3fcc508cb40ddac6c1e3" list_modules() })