Package 'ConfigINI'

Title: A Fast INI File Parser
Description: Provides a simple yet efficient parser for INI configuration files, converting them into structured list formats for easy manipulation and access within R. The structured list can seamlessly be written back to an INI configuration file, ensuring smooth round-trip data handling.
Authors: Dyfan Jones [aut, cre]
Maintainer: Dyfan Jones <[email protected]>
License: MIT + file LICENSE
Version: 0.1
Built: 2025-01-02 19:17:12 UTC
Source: https://github.com/DyfanJones/ConfigINI

Help Index


Read and Parse INI File

Description

This function reads and parses an INI file, returning its contents as a list of profiles.

Usage

read_ini(file_name)

Arguments

file_name

A character string specifying the path to the INI file.

Value

A list where each element represents a profile in the INI file. Each profile is a named list of key-value pairs. If the INI file is empty, an empty list is returned.

Examples

## Not run: 
# Example usage
ini_content <- read_ini("path/to/config.ini")
print(ini_content)

## End(Not run)

Write Configuration Data to an INI File

Description

This function converts an R list structure into an INI file format and writes it to a specified file.

Usage

write_ini(config_list, filename)

Arguments

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.

Details

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.

Value

This function does not return a value. It writes the INI file to the specified path.

Examples

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)