read.config {configr}R Documentation

Read from the file (JSON/INI/YAML/TOML be supported), retreiving all values as a list.

Description

Read from the file (JSON/INI/YAML/TOML be supported), retreiving all values as a list.

Usage

read.config(
  file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"),
  extra.list = list(),
  other.config = "",
  rcmd.parse = FALSE,
  bash.parse = FALSE,
  glue.parse = FALSE,
  glue.flag = "!!glue",
  global.vars.field = "global_vars",
  file.type = NULL,
  ...
)

Arguments

file

File name of configuration file to read from. Defaults to the value of the 'R_CONFIGFILE_ACTIVE' environment variable ('config.cfg' if the variable does not exist and JSON/INI/YAML/TOML format only)

extra.list

A list that can replace the configuration file 'debug' by list(debug = 'TRUE'), and debug will be setted to 'TRUE'

other.config

Path of another configuration file that can replace the configuration file 'key:value'

rcmd.parse

Logical wheather parse '@>@str_replace('abc', 'b', 'c')@<@' that existed in config to 'acc'

bash.parse

Logical wheather parse '#>#echo $HOME#<#' in config to your HOME PATH

glue.parse

Logical wheather parse '!!glue1:5' in config to ['1','2','3','4','5']; ['nochange', '!!glue(1:5)', 'nochange'] => ['nochange', '1', '2', '3', '4', '5', 'nochange']

glue.flag

A character flage indicating wheater run glue() function to parse (Default is !!glue)

global.vars.field

All vars defined in global.vars.field will as the extra.list params [gloval_var]

file.type

Default is no need to specify the variable, file.type will be automatically identify by get.config.type. If the value be specified, the step of filetype identification will be skipped.

...

Arguments for get.config.type, fromJSON, read.ini, yaml.load_file, parseTOML, readLines

Value

All values as a list or logical FALSE indicating that is not standard JSON/INI/YAML/TOML format file

See Also

fromJSON JSON file will read by this

read.ini INI file will read by this

yaml.load_file YAML file will read by this

parseTOML TOML file will read by this

Examples

config.json <- system.file('extdata', 'config.json', package='configr')
config <- read.config(file=config.json)
config.extra.parsed.1 <- read.config(config.json, list(debug = 'TRUE'))
other.config <- system.file('extdata', 'config.other.yaml', package='configr')
config.extra.parsed.2 <- read.config(config.json, list(debug = 'TRUE'), other.config)

[Package configr version 0.3.5 Index]