Skip to content

The function read_toml() reads TOML data from a file or a character vector, and the function write_toml() converts an R object to TOML.

Usage

read_toml(file, x = read_utf8(file), strict = TRUE)

write_toml(x, output = NULL)

toml2yaml(file, output = NULL)

yaml2toml(file, output = NULL)

Arguments

file

Path to an input (TOML or YAML) file.

x

For read_toml(), the TOML data as a character vector (it is read from file by default; if provided, file will be ignored). For write_toml(), an R object to be converted to TOML.

strict

Whether to try RcppTOML and Hugo only (i.e., not to use the naive parser). If FALSE, only the naive parser is used (this is not recommended, unless you are sure your TOML data is really simple).

output

Path to an output file. If NULL, the TOML data is returned, otherwise the data is written to the specified file.

Value

For read_toml(), an R object. For write_toml(),

toml2yaml(), and yaml2toml(), a character vector (marked by

xfun::raw_string()) of the TOML/YAML data if output = NULL, otherwise the TOML/YAML data is written to the output file.

Details

For read_toml(), it first tries to use the R package RcppTOML to read the TOML data. If RcppTOML is not available, it uses Hugo to convert the TOML data to YAML, and reads the YAML data via the R package yaml. If Hugo is not available, it falls back to a naive parser, which is only able to parse top-level fields in the TOML data, and it only supports character, logical, and numeric (including integer) scalars.

For write_toml(), it converts an R object to YAML via the R package yaml, and uses Hugo to convert the YAML data to TOML.

Examples

if (FALSE) {
v = blogdown::read_toml(x = c("a = 1", "b = true", "c = \"Hello\"", "d = [1, 2]"))
v
blogdown::write_toml(v)
}