load_opts(x, check = TRUE, envir = opts, verbose = TRUE, .parse = TRUE, ...)get_opts(x, envir = opts)set_opts(..., .dots, .parse = TRUE, envir = opts)## method for class 'opts' print(x, ...)new_opts(envir = new.env())
{{myvar}}
using previously defined options. [TRUE]Integrating params in a package:
create a options manager:
opts_mypkg = new_opts()
The object opts_mypkg
is a list of a few functions, which set, fetch and load
options (using a isolated environment). Here are a few examples:
Set some options:
opts_mypkg$set(version = '0.1', name = 'mypkg')
Fetch ALL options:
opts_mypkg$get()
OR
opts_mypkg$get("version")
to fetch a specific option.
Loading configuration files:
load_opts()
OR opts_pkg$load()
:
There are cases when options and params are actually paths to scripts or other apps or folders etc.
In such cases it might be useful to quickly check if these paths exists on the sytem.
As such, load_opts() automatically checks params ending with path|dir|exe
(if check=TRUE).
For example, values for variables like mypath
, my_path
, tool_exe
, etc would be check if they exists
and a warning would be shown if they dont exist.
Below is a list example options, retrieved via
get_opts()
:
|name |value | |default_regex |(.*) | |my_conf_path |~/flowr/conf | |my_dir |path/to/a/folder | |my_path |~/flowr | |my_tool_exe |/usr/bin/ls |
## Set options opts = set_opts(flow_run_path = "~/mypath") #OR opts = set_opts(.dots = list(flow_run_path = "~/mypath")) ## printing options, this is internally called by get_opts() print(opts)flow_run_path "~/mypath"## Fetch options get_opts()|name |value | |:-------------|:----------------| |default_regex |(.*) | |flow_run_path |~/mypath | |my_conf_path |~/flowr/conf | |my_dir |path/to/a/folder | |my_path |~/flowr | |my_tool_exe |/usr/bin/ls | |verbose |1 |get_opts("flow_run_path")flow_run_path "~/mypath"## Load options from a file fl = system.file("conf/params.conf", package = "params") load_opts(fl)Reading file, using 'V1' as id_column to remove empty rows. Warning message: Seems like these paths do not exist, this may cause issues later: |name |value | |:-----------|:----------------| |my_dir |path/to/a/folder | |my_tool_exe |/usr/bin/ls |## Create a options manager: opts_mypkg = new_opts() ## this provides three functions opts_mypkg$set(version = '0.1', name = 'mypkg') opts_mypkg$load(fl)Reading file, using 'V1' as id_column to remove empty rows. Warning message: Seems like these paths do not exist, this may cause issues later: |name |value | |:-----------|:----------------| |my_dir |path/to/a/folder | |my_tool_exe |/usr/bin/ls |opts_mypkg$get()|name |value | |:-------------|:----------------| |default_regex |(.*) | |my_conf_path |~/flowr/conf | |my_dir |path/to/a/folder | |my_path |~/flowr | |my_tool_exe |/usr/bin/ls | |name |mypkg | |verbose |2 | |version |0.1 |## Additionally, one has the options of using braces ({{}}) ## do define nested options: set_opts(first = "John", last = "Doe", full = "{{first}} {{last}}")