Learn R Programming

settings (version 0.2.7)

options_manager: Create a new options manager.

Description

Set up a set of options with default values and retrieve a manager for it.

Usage

options_manager(..., .list, .allowed)

Arguments

...

Comma separated [name]=[value] pairs. These will be the names and default values for your options manager.

.list

optional List of [name]=[value] pairs. Will be concatenated with arguments in ....

.allowed

list of named functions that check an option (see 'checking options')

Value

A function that can be used as a custom options manager. It takes as arguments a comma separated list of option names (character) to retrieve options or [name]=[value] pairs to set options.

Checking options

Option values can be checked automatically by supplying the options manager with a named list of functions (.allowed) that take an option value and throw an error if it is out-of-range. The functions inlist and inrange are convenience functions that create such checking functions for you.

Details

The function options_manager creates an option management function. The returned function can be uset to set, get, or reset options. The only restriction of the package is that the following words cannot be used as names for options:

.__reset .__defaults

For more details and extensive examples see the vignette by copy-pasting this command:

vignette("settings", package = "settings")

See Also

Reset to default values: reset.

Retrieve default values: defaults

Create a local, possibly altered copy: clone_and_merge

Examples

Run this code
# NOT RUN {
# create an options register
my_options <- options_manager(foo=1,bar=2,baz='bob')

### Retrieving options
my_options() # retrieve the full options list.
my_options('baz')
my_options('foo')

# When multiple options are retrieved, the result is a list
my_options('foo','baz')

### Setting global options
my_options(foo=3,baz='pete')
my_options()
### Reset options to default.
reset(my_options)
my_options()

### Limit the possible values for an option.
my_options <- options_manager( fu="bar",.allowed = list(fu=inlist("foo","bar")) )

# }

Run the code above in your browser using DataLab