configParser-class {ConfigParser}R Documentation

R6 object to parse an INI file

Description

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.

Methods

new(init = NULL, optionxform = tolower)

Initializes the object

Initializes the object, optionally with pre-set variables given as a list or an environment

Parameters:

init

A named character vector, named list or an environment of variables to pre-set (the will be put into the DEFAULT section)

optionxform

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:

filepath

The path to the INI file.

encoding

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:

filepath

The path to the INI file.

encoding

The encoding to use

Return:

The ConfigParser object itself

get(option, fallback, section = "default", interpolate = TRUE)

Get the value of a option

Parameters:

option

The option for which to get the value

fallback

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.

section

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

interpolate

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:

option

Name of the option to set (can be a character vector)

value

Value of the option (same length as option)

section

Character vector of length 1

error_on_new_section

Should an error be raised if the section does not exist yet

Return:

Return of the adjusted ConfigParser object itself


[Package ConfigParser version 1.0.0 Index]