Title: | An Implementation of Parsing and Writing Configuration File (JSON/INI/YAML/TOML) |
---|---|
Description: | Implements the JSON, INI, YAML and TOML parser for R setting and writing of configuration file. The functionality of this package is similar to that of package 'config'. |
Authors: | Jianfeng Li [aut, cre] |
Maintainer: | Jianfeng Li <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.5 |
Built: | 2025-02-13 05:59:20 UTC |
Source: | https://github.com/miachol/configr |
Function to access external helps about configurations format or other related information
config.help(name = NULL, show_all_names = FALSE)
config.help(name = NULL, show_all_names = FALSE)
name |
Name or number of helps |
show_all_names |
Show all urls name |
config.help() ## Not run: config.help(1) config.help('ini_git_search') ## End(Not run)
config.help() ## Not run: config.help(1) config.help('ini_git_search') ## End(Not run)
Merge list file (From config package), list.right will overwrite the element also existed in list.left
config.list.merge(list.left = list(), list.right = list())
config.list.merge(list.left = list(), list.right = list())
list.left |
One list be merged left |
list.right |
One list be merged right |
A list
config.json <- system.file('extdata', 'config.json', package='configr') list.left <- list() list.right <- eval.config(file = config.json) config.list.merge(list.left, list.right) list.left <- list(a=c(123,456)) list.right <- list(a=c(4,5,6)) config.list.merge(list.left, list.right)
config.json <- system.file('extdata', 'config.json', package='configr') list.left <- list() list.right <- eval.config(file = config.json) config.list.merge(list.left, list.right) list.left <- list(a=c(123,456)) list.right <- list(a=c(4,5,6)) config.list.merge(list.left, list.right)
Delete sections in config, just do config[sections] <- NULL
config.sections.del(config, sections)
config.sections.del(config, sections)
config |
a list of config (eg. generated by read.config) |
sections |
Sections that need to be deleted |
A list of config
config.json <- system.file('extdata', 'config.json', package = 'configr') config <- read.config(config.json, file.type = 'json') config <- config.sections.del(config, 'default')
config.json <- system.file('extdata', 'config.json', package = 'configr') config <- read.config(config.json, file.type = 'json') config <- config.sections.del(config, 'default')
Implements the YAML parser, JSON parser, INI parser and TOML parser for R setting and writing of configuration file.
Useful links:
https://github.com/Miachol/configr
Report bugs at https://github.com/Miachol/configr/issues
example.toml <- system.file('toml', 'example.toml', package='RcppTOML') is.toml <- is.toml.file(example.toml) file.type <- get.config.type(example.toml) toml.list.raw <- read.config(example.toml) owner.config <- eval.config(file = example.toml, config = 'owner') owner.config.name <- eval.config(value = 'name', file = example.toml, config = 'owner') toml.sections <- eval.config.sections(example.toml) toml.merged.all <- eval.config.merge(example.toml) toml.merged.selected <- eval.config.merge(example.toml, sections = c('database', 'owner')) others <- list(others = list(lastupdate='2017-01-07')) toml.list.update <- config.list.merge(toml.list.raw, others)
example.toml <- system.file('toml', 'example.toml', package='RcppTOML') is.toml <- is.toml.file(example.toml) file.type <- get.config.type(example.toml) toml.list.raw <- read.config(example.toml) owner.config <- eval.config(file = example.toml, config = 'owner') owner.config.name <- eval.config(value = 'name', file = example.toml, config = 'owner') toml.sections <- eval.config.sections(example.toml) toml.merged.all <- eval.config.merge(example.toml) toml.merged.selected <- eval.config.merge(example.toml, sections = c('database', 'owner')) others <- list(others = list(lastupdate='2017-01-07')) toml.list.update <- config.list.merge(toml.list.raw, others)
Covert configuration file from JSON/INI/YAML/TOML to JSON/INI/YAML
convert.config( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), out.file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), convert.to = "ini", ... )
convert.config( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), out.file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), convert.to = "ini", ... )
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) |
out.file |
Output path of configuration file. Defaults to the value of the 'R_CONFIGFILE_ACTIVE' environment variable ('config.cfg' if the variable does not exist) |
convert.to |
JSON/INI/YAML |
... |
Arguments for |
Logical indicating whether convert success
fromJSON
JSON file will read by this
read.ini
INI file will read by this
yaml.load_file
YAML file will read by this
config.json <- system.file('extdata', 'config.json', package='configr') config <- convert.config(file=config.json, out.file = sprintf('%s/config.ini', tempdir()))
config.json <- system.file('extdata', 'config.json', package='configr') config <- convert.config(file=config.json, out.file = sprintf('%s/config.ini', tempdir()))
Read from the currently active configuration (JSON/INI/YAML/TOML be supported), 'retreiving either a single named value or all values as a config obj which have 'config', 'configtype', 'file' 'property.
eval.config( value = NULL, config = Sys.getenv("R_CONFIG_ACTIVE", "default"), file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), ... )
eval.config( value = NULL, config = Sys.getenv("R_CONFIG_ACTIVE", "default"), file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), ... )
value |
Name of value (NULL to read all values) |
config |
Name of configuration to read from. Default is the value of 'the R_CONFIG_ACTIVE environment variable (Set to 'default' if the variable does not exist). |
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) |
... |
Arguments for |
Either a single value or all values as a list or logical FALSE indicating that is not standard JSON/INI/YAML/TOML format file
read.config
read config by this
eval.config.merge
which can merge multiple parameter sets by sections
config.json <- system.file('extdata', 'config.json', package='configr') config <- eval.config(file=config.json) config.extra.parsed.1 <- eval.config(file = config.json, extra.list = list(debug = 'TRUE')) other.config <- system.file('extdata', 'config.other.yaml', package='configr') config.extra.parsed.2 <- eval.config(file = config.json, extra.list = list(debug = 'TRUE'), other.config = other.config)
config.json <- system.file('extdata', 'config.json', package='configr') config <- eval.config(file=config.json) config.extra.parsed.1 <- eval.config(file = config.json, extra.list = list(debug = 'TRUE')) other.config <- system.file('extdata', 'config.other.yaml', package='configr') config.extra.parsed.2 <- eval.config(file = config.json, extra.list = list(debug = 'TRUE'), other.config = other.config)
Merge config parameter sets by sections.
eval.config.merge( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), sections = NULL, ... )
eval.config.merge( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), sections = NULL, ... )
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) |
sections |
Need be merged parameter sets, eg. sections=c('default', 'version'), will default to all of config sections |
... |
Arguments for |
A list or logical FALSE indicating that is not standard JSON/INI/YAML/TOML format file
eval.config.sections
which only get all of the mainly parameter sets name in config file,
read.config
which only read from a config as a list,
eval.config
which only read one sections as config obj or a value from config file.
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') eval.config.merge(config.json) eval.config.merge(config.ini) eval.config.merge(config.yaml) eval.config.merge(config.toml)
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') eval.config.merge(config.json) eval.config.merge(config.ini) eval.config.merge(config.yaml) eval.config.merge(config.toml)
Get config file parameter sections
eval.config.sections( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), ... )
eval.config.sections( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), ... )
file |
File name of configuration file to read from. Default is the value of the 'R_CONFIGFILE_ACTIVE' environment variable (Set to 'config.cfg' if the variable does not exist and JSON/INI/YAML/TOML format only) |
... |
Arguments for |
a character vector including the sections infomation of configure file or logical FALSE indicating that is not standard JSON/INI/YAML/TOML format file
eval.config.merge
use this function to get all of sections of config file.
config.json <- system.file('extdata', 'config.json', package='configr') eval.config.sections(config.json)
config.json <- system.file('extdata', 'config.json', package='configr') eval.config.sections(config.json)
Fetch configuration file and generate a merged list
fetch.config( links, return.files = FALSE, destdir = normalizePath("./"), keep.basename = TRUE, ... )
fetch.config( links, return.files = FALSE, destdir = normalizePath("./"), keep.basename = TRUE, ... )
links |
Url or files path that need to be merged, e.g. /tmp/config, http://, ftp://. |
return.files |
Only save the links configuration files to destdir and not to read and merge the configuration files, default is FALSE |
destdir |
Fetch configuration files and copy to this directory, default is ./ |
keep.basename |
Whather use the links basename as the saved name or use paste0(tempfile(), '_configr') |
... |
Extra parameters pass to |
A list or a vector
links <- c(paste0('https://raw.githubusercontent.com/JhuangLab', '/BioInstaller/master/inst/extdata/config/db/db_annovar.toml'), paste0('https://raw.githubusercontent.com/JhuangLab/BioInstaller', '/master/inst/extdata/config/db/db_main.toml'), system.file('extdata', 'config.toml', package = 'configr')) x <- fetch.config(links)
links <- c(paste0('https://raw.githubusercontent.com/JhuangLab', '/BioInstaller/master/inst/extdata/config/db/db_annovar.toml'), paste0('https://raw.githubusercontent.com/JhuangLab/BioInstaller', '/master/inst/extdata/config/db/db_main.toml'), system.file('extdata', 'config.toml', package = 'configr')) x <- fetch.config(links)
Get config file type retreiving json/ini/yaml or FALSE
get.config.type(file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), ...)
get.config.type(file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), ...)
file |
File name of configuration file to test. 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) |
... |
Arguments for |
Character json/ini/yaml/toml or Logical FALSE indicating that is not standard JSON/INI/YAML/TOML format file
is.json.file
,
is.ini.file
,
is.yaml.file
,
is.toml.file
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') get.config.type(file=config.json) get.config.type(file=config.ini) get.config.type(file=config.yaml) get.config.type(file=config.toml)
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') get.config.type(file=config.json) get.config.type(file=config.ini) get.config.type(file=config.yaml) get.config.type(file=config.toml)
Check whether a configuration group is currently active
is.config.active(config)
is.config.active(config)
config |
Configuration name |
Logical indicating whether the specified configuration is active
is.config.active('default')
is.config.active('default')
Check whether a configuration file is currently active
is.configfile.active(config.file)
is.configfile.active(config.file)
config.file |
Configuration filename |
Logical indicating whether the specified configuration file is active
is.configfile.active('config.cfg')
is.configfile.active('config.cfg')
Function to check wheather file is INI format
is.ini.file( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), ini.file.debug = FALSE, ... )
is.ini.file( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), ini.file.debug = FALSE, ... )
file |
File name of configuration file to test. 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) |
ini.file.debug |
If TRUE, it will show error infomation when read INI config, default is FALSE |
... |
Arguments for |
Logical indicating whether the specified configuration file is INI format
is.json.file
,
is.yaml.file
,
is.toml.file
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') print(is.ini.file(config.ini)) print(is.ini.file(config.json)) print(is.ini.file(config.yaml)) print(is.ini.file(config.toml))
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') print(is.ini.file(config.ini)) print(is.ini.file(config.json)) print(is.ini.file(config.yaml)) print(is.ini.file(config.toml))
Function to check wheather file is JSON format
is.json.file( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), json.file.debug = FALSE, ... )
is.json.file( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), json.file.debug = FALSE, ... )
file |
File name of configuration file to test. 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) |
json.file.debug |
If TRUE, it will show error infomation when read JSON config, default is FALSE |
... |
Logical indicating whether the specified configuration file is JSON format
is.ini.file
,
is.yaml.file
,
is.toml.file
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') print(is.json.file(config.json)) print(is.json.file(config.ini)) print(is.json.file(config.yaml)) print(is.json.file(config.toml))
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') print(is.json.file(config.json)) print(is.json.file(config.ini)) print(is.json.file(config.yaml)) print(is.json.file(config.toml))
Function to check wheather file is TOML format
is.toml.file( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), toml.file.debug = FALSE, ... )
is.toml.file( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), toml.file.debug = FALSE, ... )
file |
File name of configuration file to test. 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) |
toml.file.debug |
If TRUE, it will show error infomation when read TOML config, default is FALSE |
... |
Arguments for |
Logical indicating whether the specified configuration file is TOML format
is.json.file
is.ini.file
,
is.yaml.file
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') print(is.toml.file(config.json)) print(is.toml.file(config.ini)) print(is.toml.file(config.yaml)) print(is.toml.file(config.toml))
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') print(is.toml.file(config.json)) print(is.toml.file(config.ini)) print(is.toml.file(config.yaml)) print(is.toml.file(config.toml))
Function to check wheather file is YAML format
is.yaml.file( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), yaml.file.debug = FALSE, ... )
is.yaml.file( file = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), yaml.file.debug = FALSE, ... )
file |
File name of configuration file to test. 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) |
yaml.file.debug |
If TRUE, it will show error infomation when read YAML config, default is FALSE |
... |
Arguments for |
Logical indicating whether the specified configuration file is YAML format
is.json.file
,
is.ini.file
,
is.toml.file
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') print(is.yaml.file(config.yaml)) print(is.yaml.file(config.json)) print(is.yaml.file(config.ini)) print(is.yaml.file(config.toml))
config.json <- system.file('extdata', 'config.json', package='configr') config.ini <- system.file('extdata', 'config.ini', package='configr') config.yaml <- system.file('extdata', 'config.yaml', package='configr') config.toml <- system.file('extdata', 'config.toml', package='configr') print(is.yaml.file(config.yaml)) print(is.yaml.file(config.json)) print(is.yaml.file(config.ini)) print(is.yaml.file(config.toml))
Parse the configuration var format, and replace it by extra.list values
parse.extra( config, extra.list = list(), other.config = "", rcmd.parse = FALSE, bash.parse = FALSE, glue.parse = FALSE, glue.flag = "!!glue", global.vars.field = "global_vars" )
parse.extra( config, extra.list = list(), other.config = "", rcmd.parse = FALSE, bash.parse = FALSE, glue.parse = FALSE, glue.flag = "!!glue", global.vars.field = "global_vars" )
config |
A list that were generated by read.config/eval.config/eval.config.merge |
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')@<@' 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 flag 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] |
A list
config.json <- system.file('extdata', 'config.json', package='configr') config.other <- system.file('extdata', 'config.other.yaml', package='configr') config <- read.config(config.json) parse.extra(config, list(debug = 'TRUE')) parse.extra(config, list(debug = 'TRUE'), other.config = config.other) parse.extra(config, list(debug = 'TRUE'), other.config = config.other, rcmd.parse = TRUE) parse.extra(config, list(debug = 'TRUE'), other.config = config.other, rcmd.parse = TRUE, bash.parse = TRUE) raw <- c('a', '!!glue{1:5}', 'c') expect.parsed.1 <- c('a', '1', '2', '3', '4', '5', 'c') list.raw <- list(glue = raw, nochange = 1:10) parsed <- parse.extra(list.raw, glue.parse = TRUE) raw <- c('!!glue_numeric{1:5}') expect.parsed.1 <- c(1, 2, 3, 4, 5) list.raw <- list(glue = raw, nochange = 1:10) parsed <- parse.extra(list.raw, glue.parse = TRUE)
config.json <- system.file('extdata', 'config.json', package='configr') config.other <- system.file('extdata', 'config.other.yaml', package='configr') config <- read.config(config.json) parse.extra(config, list(debug = 'TRUE')) parse.extra(config, list(debug = 'TRUE'), other.config = config.other) parse.extra(config, list(debug = 'TRUE'), other.config = config.other, rcmd.parse = TRUE) parse.extra(config, list(debug = 'TRUE'), other.config = config.other, rcmd.parse = TRUE, bash.parse = TRUE) raw <- c('a', '!!glue{1:5}', 'c') expect.parsed.1 <- c('a', '1', '2', '3', '4', '5', 'c') list.raw <- list(glue = raw, nochange = 1:10) parsed <- parse.extra(list.raw, glue.parse = TRUE) raw <- c('!!glue_numeric{1:5}') expect.parsed.1 <- c(1, 2, 3, 4, 5) list.raw <- list(glue = raw, nochange = 1:10) parsed <- parse.extra(list.raw, glue.parse = TRUE)
Read from the file (JSON/INI/YAML/TOML be supported), retreiving all values as a list.
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, ... )
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, ... )
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 |
... |
Arguments for |
All values as a list or logical FALSE indicating that is not standard JSON/INI/YAML/TOML format file
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
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)
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)
Parse configuration string to R list object.
str2config(text, ...)
str2config(text, ...)
text |
JSON, YAML, INI or TOML format string. |
... |
Arguments pass to |
List
json_string <- '{"city" : "Crich"}\n' yaml_string <- 'foo: 123\n' json_config <- str2config(json_string) yaml_config <- str2config(yaml_string)
json_string <- '{"city" : "Crich"}\n' yaml_string <- 'foo: 123\n' json_config <- str2config(json_string) yaml_config <- str2config(yaml_string)
Write config in a file (JSON/YAML/INI)
write.config( config.dat, file.path = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), write.type = "ini", sections = NULL, ... )
write.config( config.dat, file.path = Sys.getenv("R_CONFIGFILE_ACTIVE", "config.cfg"), write.type = "ini", sections = NULL, ... )
config.dat |
a list of config (eg. generated by read.config) |
file.path |
File path of configuration to write. Defaults to the value of the 'R_CONFIGFILE_ACTIVE' environment variable ('config.cfg' if the variable does not exist) |
write.type |
json/ini/yaml |
sections |
Sections that need be write in file, default is NULL and use all of sections |
... |
Arguments for |
Logical indicating whether the specified configuration file be writed successful
toJSON
convert a list to JSON string,
prettify
convert a JSON string to user friendly view,
write.ini
write a list in a INI format file,
as.yaml
convert a list to YAML format
list.test <- list(a=c(123,456)) out.yaml <- sprintf('%s/test.yaml', tempdir()) write.config(list.test, out.yaml, write.type = 'yaml')
list.test <- list(a=c(123,456)) out.yaml <- sprintf('%s/test.yaml', tempdir()) write.config(list.test, out.yaml, write.type = 'yaml')