RcppTOML (version 0.1.5)

parseTOML: Parse a TOML configuration file

Description

The parseTOML function parses ‘TOML’ (for ‘Tom's Obvious Markup Language’) files. The TOML format both highly readable and expressive, allows comments, indentation and other aspects suitable for human readers, contains typed objects yet allows everything similar configuration languages permit.

Usage

parseTOML(input, verbose = FALSE, fromFile=TRUE, includize=FALSE, escape=TRUE)

# S3 method for toml print (x, ...) # S3 method for toml summary (object, ...)

Arguments

input

A character object either denoting a path and file (where tilde-expansion is performed as well) from parsing from file, or a containing a suitable ‘TOML’ expression that is parsed from this expression.

verbose

A logical switch to turn on (very) verbose operation which can be useful in debugging a parsing issue in a file.

fromFile

A logical switch indicating whether input is interpreted as a filename (with path) which is to be parsed, or a whether the ‘TOML’ expression in the string is parsed; default is file mode.

includize

A logical switch indicating whether the includize stream buffer class for (non-standard but very useful) include statements should be used.

escape

A logical switch indicating whether special characters in strings (namely new line, double quotation mark and backslash) should be escaped in both printed output (when verbose = TRUE) and returned values or only in the printed output. Defaults to TRUE for the sake of backward compatibility.

x

A toml object.

object

A toml object.

...

Furter arguments.

Value

A toml object is returned, which is really just a list object with a class attribute to allow for print and summary methods.

Details

The package uses the ‘cpptoml’ C++11 parser by Charles Geigle. This requires a recent-enough C++11 compiler which excludes one deployed by Rtools on Windows at the time the package was initially put together.

Following TOML specification this package assumes that any file input is a UTF-8 encoded text file. Any non-file input (when fromFile = FALSE) is converted to UTF-8 if necessary (using R's enc2utf(). Note that the conversion to UTF-8 may fail for input with "unknown" declared encoding if the true encoding does not match system's locale.

References

TOML: https://github.com/toml-lang/toml cpptoml: https://github.com/skystrife/cpptoml

Examples

Run this code
# NOT RUN {
  library(RcppTOML)

  file <- system.file("toml", "example.toml", package="RcppTOML")

  toml <- parseTOML(file)  # given file, return parsed object

  summary(toml)            # really sparse summary method
  print(toml)              # print is a wrapper around str()

  txt <- "value='''\nHello\nWorld!'''"      # input with \n is ..
  parseTOML(input = txt, fromFile = FALSE)  # ... (doubly) escaped by default
  parseTOML(input = txt, fromFile = FALSE, escape = FALSE) # ... kept 'as is'

# }

Run the code above in your browser using DataCamp Workspace