Title: | Minimal and Lightweight Configuration Tool |
---|---|
Description: | Minimal and lightweight configuration tool that provides basic support for 'YAML' configuration files without requiring additional package dependencies. It offers a simple method for loading and parsing configuration settings, making it ideal for quick prototypes and lightweight projects. |
Authors: | Yaoxiang Li [cre, aut] |
Maintainer: | Yaoxiang Li <[email protected]> |
License: | GPL-3 |
Version: | 0.1.2 |
Built: | 2025-03-04 05:25:52 UTC |
Source: | https://github.com/cran/rconf |
Reads a YAML configuration file (default "config.yml") and returns the configuration stored under the specified key (default "default"). This function merges the functionality of loading the file and parsing its contents into a list. It uses UTF-8 encoding to read the file and then processes it with a minimal YAML parser.
get_config(file = "config.yml", config_name = "default")
get_config(file = "config.yml", config_name = "default")
file |
Path to the YAML configuration file. For example, to load the sample configuration provided in the package extdata directory, use: 'system.file("extdata", "config.yml", package = "rconf")'. |
config_name |
The key in the configuration to extract (e.g., "default"). If the key exists in the parsed configuration list, only that sub-list is returned. |
If the parsed configuration list contains a component with the name specified by 'config_name', only that component is returned. Otherwise, the entire configuration list is returned.
A list of configuration settings. When the configuration file contains multiple sections, and the section matching 'config_name' is found, only that section is returned. Otherwise, the full configuration list is returned.
Yaoxiang Li
# Example: Load sample configuration from the extdata directory. cfg <- get_config(system.file("extdata", "config.yml", package = "rconf"), config_name = "default") # Access specific configuration settings: print(cfg$raw_data_dir) print(cfg$processed_data_dir)
# Example: Load sample configuration from the extdata directory. cfg <- get_config(system.file("extdata", "config.yml", package = "rconf"), config_name = "default") # Access specific configuration settings: print(cfg$raw_data_dir) print(cfg$processed_data_dir)
Recursively merges two configuration lists, with values in the override replacing those in the base configuration.
merge_configs(base_cfg, override_cfg)
merge_configs(base_cfg, override_cfg)
base_cfg |
A list containing the base configuration. |
override_cfg |
A list containing override values. |
A merged configuration list.
base_cfg <- get_config(system.file("extdata", "config.yml",package = "rconf"), config_name = "default") dev_cfg <- get_config(system.file("extdata", "config.yml", package = "rconf"), config_name = "development") combined_cfg <- merge_configs(base_cfg, dev_cfg) print(combined_cfg)
base_cfg <- get_config(system.file("extdata", "config.yml",package = "rconf"), config_name = "default") dev_cfg <- get_config(system.file("extdata", "config.yml", package = "rconf"), config_name = "development") combined_cfg <- merge_configs(base_cfg, dev_cfg) print(combined_cfg)