settings (version 0.2.4)

clone_and_merge: Create a local, altered copy of an options manager

Description

Local options management.

Usage

clone_and_merge(options, ...)

Arguments

options

A function as returned by options_manager or clone_and_merge.

...

Options to be merged, in the form of [name]=[value] pairs.

Value

A option manager like options, with possibly different settings.

Details

This function creates a copy of the options manager options, with the same defaults. However, the current settings may be altered by passing extra arguments. Its intended use is to allow for easy merging of local options with global settings in a function call.

Some more examples can be found in the vignette: vignette('settings',package='options').

See Also

options_manager, reset, defaults

Examples

Run this code
# NOT RUN {
# Create global option manager.
opt <- options_manager(foo=1,bar='a')

# create an altered copy
loc_opt <- clone_and_merge(opt, foo=2)

# this has no effect on the 'global' version
opt()
# but the local version is different
loc_opt()

# we alter the global version and reset the local version
opt(foo=3)
reset(loc_opt)
opt()
loc_opt()

# create an options manager with some option values limited
opt <- options_manager(prob=0.5,y='foo',z=1,
  .allowed=list(
     prob = inrange(min=0,max=1)
     , y    = inlist("foo","bar")
   )
 )
# change an option
opt(prob=0.8)
opt("prob")
# }
# NOT RUN {
# this gives an error
opt(prob=2)
# }

Run the code above in your browser using DataCamp Workspace