read_toml: Read and write TOML data (Tom's Obvious Markup Language)

View source: R/utils.R

read_tomlR Documentation

Read and write TOML data (Tom's Obvious Markup Language)

Description

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.

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.

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.

Examples

## Not run: 
v = blogdown::read_toml(x = c("a = 1", "b = true", "c = \"Hello\"", "d = [1, 2]"))
v
blogdown::write_toml(v)

## End(Not run)

blogdown documentation built on May 29, 2024, 8:55 a.m.

Related to read_toml in blogdown...