Setting/loading and extracting various options into the environment


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())


  • get_opts: a character vector of names of options to extract.
  • load_opts: path to a configuration file
load_opts(): in case of a configuration file, whether to check if files defined in parameters exists. [TRUE]
environ used to store objects. Default is a environ object called opts [params:::opts]
load_opts(): Logical variable indicate level of verboseness [TRUE]
set_opts(), load_opts(): logical, whether to auto-complete {{myvar}} using previously defined options. [TRUE]
set_opts(): a named set of variable/value pairs seperated by comma
set_opts(): A named list, as a alternative to ...


  • set_opts(): set options into a custom envir
  • get_opts(): extract options
  • load_opts(): Read a tab delimted file using read_sheet and load them as options using set_opts
  • new_opts(): create a options manager to be included in a pacakge
  • print.opts(): print pkg options as a pretty table


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


	|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 |
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 |
|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}}")