OptionList: Make an Option List

Description Usage Arguments Value Examples

Description

This function was copied from knitr:::new_defaults. It encloses the default values inside of a list's environment and uses functions stored in that list to manipulate and retrieve those defaults.

Usage

1
OptionList(value = list())

Arguments

value

a list of options and their respective values

Value

an OptionList containing four functions: $get(name, default = FALSE) to get the value of an option name, $set(...) for setting option values, $merge(values) for internally merging lists of options, $restore(...) for restoring the original default values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
lwl_opts <- OptionList(list(
  interpolation_window = 100,
  timeslice_start = -200,
  timeslice_end = 2000
))

lwl_opts$get()
# $interpolation_window
# [1] 100
#
# $timeslice_start
# [1] -200
#
# $timeslice_end
# [1] 2000

# Set new values
lwl_opts$set(interpolation_window = 200, timeslice_start = 250)
lwl_opts$get("interpolation_window")
# [1] 200

# Get the default window value
lwl_opts$get("interpolation_window", default = TRUE)
# $interpolation_window
# [1] 100

# Restore defaluts
lwl_opts$restore()

# The `print(...)` method for an `OptionList` just prints `$get(...)`
lwl_opts
# $interpolation_window
# [1] 100
#
# $timeslice_start
# [1] -200
#
# $timeslice_end
# [1] 2000

tjmahr/lookr documentation built on May 31, 2019, 3:41 p.m.