Title: | Fast INI File Parser for R |
---|---|
Description: | Provide a simple 'INI' file parser to structured list format. Using the 'C' library 'inih' <https://github.com/benhoyt/inih> as backend of fast performance. |
Authors: | Dyfan Jones [aut, cre], Ben Hoyt [aut, cph] (Author of bundled inih) |
Maintainer: | Dyfan Jones <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1 |
Built: | 2024-12-31 13:25:07 UTC |
Source: | https://github.com/DyfanJones/inih |
This function reads an INI file and converts its contents into an R list structure.
read_ini(filename)
read_ini(filename)
filename |
A string specifying the path to the input INI file. |
The read_ini
function parses the specified INI file and converts its sections
and key-value pairs into a nested R list. Each section in the INI file becomes
a named list within the result, and each key-value pair within a section becomes
an element of that list.
If the INI file cannot be loaded, the function will raise an error.
A named list where each element is itself a named list representing sections and key-value pairs of the configuration data.
config <- list( section1 = list( key1 = "value1" ), section2 = list( keyA = "valueA", keyB = "valueB" ) ) ini_file <- tempfile() write_ini(config, ini_file) read_ini(ini_file) unlink(ini_file)
config <- list( section1 = list( key1 = "value1" ), section2 = list( keyA = "valueA", keyB = "valueB" ) ) ini_file <- tempfile() write_ini(config, ini_file) read_ini(ini_file) unlink(ini_file)
This function converts an R list structure into an INI file format and writes it to a specified file.
write_ini(config_list, filename)
write_ini(config_list, filename)
config_list |
A named list where each element is itself a named list representing sections and key-value pairs of the configuration data. |
filename |
A string specifying the path to the output INI file. |
The config_list
parameter should be a named list where each top-level name represents a section in the INI file.
Each section should be a named list where the names are the keys and the values are the corresponding values in the INI file.
Numeric values are converted to strings before being written to the file.
If the config_list
is empty, an empty INI file will be created.
This function does not return a value. It writes the INI file to the specified path.
config <- list( section1 = list( key1 = "value1", key2 = 123 ), section2 = list( keyA = "valueA", keyB = "valueB" ) ) ini_file <- tempfile() write_ini(config, ini_file) unlink(ini_file)
config <- list( section1 = list( key1 = "value1", key2 = 123 ), section2 = list( keyA = "valueA", keyB = "valueB" ) ) ini_file <- tempfile() write_ini(config, ini_file) unlink(ini_file)