Title: | Package to Parse an INI File, Including Variable Interpolation |
---|---|
Description: | Enhances the 'ini' package by adding the ability to interpolate variables. The INI configuration file is read into an R6 ConfigParser object (loosely inspired by Pythons ConfigParser module) and the keys can be read, where '%(....)s' instances are interpolated by other included options or outside variables. |
Authors: | Holger Hoefling [aut, cre] |
Maintainer: | Holger Hoefling <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2025-03-11 02:43:50 UTC |
Source: | https://github.com/hhoeflin/configparser |
This class creates an object that represents an INI file. It
also supports interpolation of variables of the form %(...)s
.
More detail on how the interpolation works in given in the
explanation of method get
.
new(init = NULL, optionxform = tolower)
Initializes the object
Initializes the object, optionally with pre-set variables given as a list or an environment
Parameters:
A named character vector, named list or an environment of variables to pre-set (the will be
put into the DEFAULT
section)
Function through which all option and section names are funneled. By default tolower
to make all names lowercase. To switch off, pass in identity
read(filepath, encoding = getOption("encoding"))
Read in an INI file
Reads the INI given into the object. It will be added to the internal storage of the object. If applying these functions several times, later definitions overwrite those that were read earlier.
Parameters:
The path to the INI file.
The encoding to use
Return:
The object, but with the added data of the file
write(filepath, encoding = getOption("encoding"))
Write an INI file
Write the ConfigParser object into the INI file. It writes all the different sections using uninterpolated variables.
Parameters:
The path to the INI file.
The encoding to use
Return:
The ConfigParser object itself
get(option, fallback, section = "default", interpolate = TRUE)
Get the value of a option
Parameters:
The option for which to get the value
The fallback value to return if there is no value for the option. If missing, an error will be thrown if the option has no value.
The section (or several) from which to read the option. It will try to read the
option in the given section from first to last, with DEFAULT
always being the
last
Should the values be interpolated. This will try to replace variables of
the form %(...)s
Return:
The value of the option
getboolean(option, fallback, section = "default", interpolate = TRUE)
Same as get
, but results coerced to a logical.
getfloat(option, fallback, section = "default", interpolate = TRUE)
Same as get
, but the result coerced to a float.
set(option, value, section, error_on_new_section = TRUE)
Set option to a value in a section
Sets an option to the given value (which can include variables for interpolation) in the given section.
Parameters:
Name of the option to set (can be a character vector)
Value of the option (same length as option
)
Character vector of length 1
Should an error be raised if the section does not exist yet
Return:
Return of the adjusted ConfigParser
object itself