Construct a module provider intended for defining modules that can be used as general purpose options and configuration containers.

options_provider(...)

Arguments

...

Named arguments used as default options. If void, no default option is set.

Value

A module provider which exposes an R environment. The default options arguments, if any, are used to assign the values to their corresponding names in the returned environment.

Syntactic Sugars

name %provides_options% options

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, make, %provides%, %requires%, reset, and touch.

Examples

#> [2017-06-21T21:58:28 UTC] Resetting modulr state ... OK
"foo/config" %provides% options_provider(upper = FALSE)
#> [2017-06-21T21:58:28 UTC] Defining 'foo/config' ... OK
"foo" %requires% list(config = "foo/config") %provides% { function() casefold("foo", upper = config$upper) }
#> [2017-06-21T21:58:28 UTC] Defining 'foo' ... OK
foo %<=% "foo"
#> [2017-06-21T21:58:28 UTC] Making 'foo' ... #> [2017-06-21T21:58:28 UTC] * Visiting and defining dependencies ... #> [2017-06-21T21:58:28 UTC] * Constructing dependency graph ... OK #> [2017-06-21T21:58:28 UTC] DONE ('foo' in 0.014 secs)
foo()
#> Error in eval(expr, envir, enclos): could not find function "foo"
config %<=% "foo/config"
#> [2017-06-21T21:58:28 UTC] Making 'foo/config' ... #> [2017-06-21T21:58:28 UTC] * Visiting and defining dependencies ...
#> Error: "foo/config" is not defined.
config$upper <- TRUE
#> Error in config$upper <- TRUE: object 'config' not found
foo()
#> Error in eval(expr, envir, enclos): could not find function "foo"
"foo/config" %provides_options% list(upper = FALSE) foo %<=% "foo"
#> [2017-06-21T21:58:28 UTC] Making 'foo' ... #> [2017-06-21T21:58:28 UTC] * Visiting and defining dependencies ... #> [2017-06-21T21:58:28 UTC] * Constructing dependency graph ... OK #> [2017-06-21T21:58:28 UTC] DONE ('foo' in 0.013 secs)
foo()
#> Error in eval(expr, envir, enclos): could not find function "foo"
touch("foo/config")
#> [2017-06-21T21:58:28 UTC] Touching 'foo/config' ... OK
"foo/config" %provides_options% list(upper = FALSE)
#> [2017-06-21T21:58:28 UTC] Re-defining 'foo/config' ... OK
foo %<=% "foo"
#> [2017-06-21T21:58:28 UTC] Making 'foo' ... #> [2017-06-21T21:58:28 UTC] * Visiting and defining dependencies ... #> [2017-06-21T21:58:28 UTC] * Constructing dependency graph ... OK #> [2017-06-21T21:58:28 UTC] DONE ('foo' in 0.016 secs)
foo()
#> Error in eval(expr, envir, enclos): could not find function "foo"