Package ‘configr’

January 16, 2017 Title An Implementation of Parsing and Writing Configuration File (JSON/INI/YAML) Version 0.0.3 Description Implements the YAML parser, JSON parser and INI parser for R setting and writ- ing of configuration file. The functionality of this package is similar to that of package 'config'. Depends R (>= 3.2.1)

URL https://github.com/Miachol/configr License MIT + file LICENSE Encoding UTF-8 LazyData true Imports stringr (>= 1.0.0), jsonlite (>= 1.2), ini (>= 0.2), futile.logger (>= 1.4.1), tools (>= 3.1.1), (>= 2.1.3), config (>= 0.2) RoxygenNote 5.0.1 Suggests knitr, rmarkdown, testthat NeedsCompilation no Author Jianfeng Li [aut, cre] Maintainer Jianfeng Li Repository CRAN Date/Publication 2017-01-16 16:49:17

R topics documented:

config.list.merge ...... 2 configr ...... 3 eval.config ...... 3 eval.config.groups ...... 4 eval.config.merge ...... 5 get.config.type ...... 5 is.ini.file ...... 6

1 2 config.list.merge

is..file ...... 7 is.yaml.file ...... 8 read.config ...... 8 write.config ...... 9

Index 11

config.list.merge Merge list file (From config package), list.right will overwrite the ele- ment also existed in list.left

Description

Merge list file (From config package), list.right will overwrite the element also existed in list.left

Usage

config.list.merge(list.left = list(), list.right = list())

Arguments

list.left One list be merged left list.right One list be merged right

Value

a list

See Also

merge call in this function

Examples

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) configr 3

configr configr package implements the YAML parser, JSON parser and INI parser for R setting and writing of configuration file.

Description configr package implements the YAML parser, JSON parser and INI parser for R setting and writing of configuration file.

Author(s) Li Jianfeng [email protected]

See Also Useful links: https://github.com/Miachol/configr Report bugs at https://github.com/Miachol/configr/issues

eval.config Read from the currently active configuration (JSON/INI/YAML be sup- ported), ’retreiving either a single named value or all values as a con- fig obj which have ’config’, ’configtype’, ’file’ ’property.

Description Read from the currently active configuration (JSON/INI/YAML be supported), ’retreiving either a single named value or all values as a config obj which have ’config’, ’configtype’, ’file’ ’property.

Usage eval.config(value = NULL, config = Sys.getenv("R_CONFIG_ACTIVE", "default"), file = "config.json", encoding = getOption("encoding"))

Arguments value Name of value (NULL to read all values) config Name of configuration to read from. Defaults to the value of ’the R_CONFIG_NAME environment variable (’default’ if the variable does not exist). file Configuration file to read from (defaults to ’config.json’) ’JSON/INI/YAML for- mat file. encoding Encoding of filepath parameter, will default to system encoding if not specifield 4 eval.config.groups

Value Either a single value or all values as a list.

See Also read.config read config by this eval.config.merge which can merge multiple parameter sets by groups

Examples

config.json <- system.file('extdata', 'config.json', package='configr') config <- eval.config(file=config.json)

eval.config.groups Get config file parameter groups

Description Get config file parameter groups

Usage eval.config.groups(file = "config.json", encoding = getOption("encoding"))

Arguments file Configuration file to read from (defaults to ’config.json’) ’JSON/INI/YAML for- mat file. encoding Encoding of filepath parameter, will default to system encoding if not specifield

Value a vector including the groups infomation of configure file

See Also eval.config.merge which use this get all of parameter sets groups of config file.

Examples

config.json <- system.file('extdata', 'config.json', package='configr') eval.config.groups(config.json) eval.config.merge 5

eval.config.merge Merge config parameter sets by groups.

Description Merge config parameter sets by groups.

Usage eval.config.merge(file = "config.json", groups = NULL, encoding = getOption("encoding"))

Arguments file Configuration file to read from (defaults to ’config.json’) ’JSON/INI/YAML for- mat file. groups Need be merged parameter sets, eg. groups=c(’default’, ’version’), will default to all of config groups encoding Encoding of filepath parameter, will default to system encoding if not specifield

Value a list

See Also eval.config.groups 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 groups as config obj or a value from config file.

Examples config.json <- system.file('extdata', 'config.json', package='configr') eval.config.merge(config.json)

get.config.type Get config file type retreiving json/ini/yaml or FALSE

Description Get config file type retreiving json/ini/yaml or FALSE

Usage get.config.type(file = "config.json", encoding = getOption("encoding")) 6 is.ini.file

Arguments

file Configuration file to read from (defaults to ’config.json’) ’JSON/INI/YAML for- mat file. encoding Encoding of filepath parameter, will default to system encoding if not specifield

Value

json/ini/yaml or FALSE

See Also

is.json.file/is.ini.fileis.yaml.file/

Examples

config.json <- system.file('extdata', 'config.json', package='configr') get.config.type(file=config.json)

is.ini.file Function to check wheather file is ini format

Description

Function to check wheather file is ini format

Usage

is.ini.file(file, encoding = getOption("encoding"))

Arguments

file filename to be coerced or tested encoding Encoding of filepath parameter, will default to system encoding if not specifield

Value

TRUE/FALSE

See Also

is.json.file/is.yaml.file is.json.file 7

Examples

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') print(is.ini.file(config.ini)) print(is.ini.file(config.json)) print(is.ini.file(config.yaml))

is.json.file Function to check wheather file is json format

Description

Function to check wheather file is json format

Usage

is.json.file(file, encoding = getOption("encoding"))

Arguments

file filename to be coerced or tested encoding Encoding of filepath parameter, will default to system encoding if not specifield

Value

TRUE/FALSE

See Also

is.ini.file/is.yaml.file

Examples

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') print(is.json.file(config.json)) print(is.json.file(config.ini)) print(is.json.file(config.yaml)) 8 read.config

is.yaml.file Function to check wheather file is YAML format

Description Function to check wheather file is YAML format

Usage is.yaml.file(file, encoding = getOption("encoding"))

Arguments file filename to be coerced or tested encoding Encoding of filepath parameter, will default to system encoding if not specifield

Value TRUE/FALSE

See Also is.json.file/is.ini.file

Examples 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') print(is.yaml.file(config.yaml)) print(is.json.file(config.json)) print(is.ini.file(config.ini))

read.config Read from the file (JSON/INI/YAML be supported), retreiving all val- ues as a list.

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

Usage read.config(file = "config.json", encoding = getOption("encoding")) write.config 9

Arguments file Configuration file to read from (defaults to ’config.json’) ’JSON/INI/YAML for- mat file. encoding Encoding of filepath parameter, will default to system encoding if not specifield.

Value All values as a list.

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

Examples config.json <- system.file('extdata', 'config.json', package='configr') config <- read.config(file=config.json)

write.config Write config in a file (JSON/YAML/INI)

Description Write config in a file (JSON/YAML/INI)

Usage write.config(config.dat, file.path, write.type = "ini", encoding = getOption("encoding"), YAML.indent = 2)

Arguments config.dat a list of config (eg. generated by read.config) file.path file to write write.type json/ini/yaml encoding, Encoding of filepath parameter, will default to system encoding if not specifield YAML.indent if write.type is yaml, the YAML file indent will be setted by this

Value TRUE/FALSE 10 write.config

See Also 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.

Examples list.test <- list(a=c(123,456)) out.yml <- sprintf('%s/test.yaml', tempdir()) write.config(list.test, out.yml, write.type = 'yaml') Index

as.yaml, 10 config.list.merge,2 configr,3 configr-package (configr),3 eval.config,3, 5 eval.config.groups,4, 5 eval.config.merge, 4,5 fromJSON, 9 get.config.type,5 is.ini.file, 6,6, 7,8 is.json.file, 6,7, 8 is.yaml.file, 6,7 ,8 merge, 2 prettify, 10 read.config, 4,5 ,8 read.ini, 9 toJSON, 10 write.config,9 write.ini, 10 yaml.load_file, 9

11