Learn R Programming

xfun (version 0.50)

taml_load: A simple YAML reader and writer

Description

TAML is a tiny subset of YAML. See https://yihui.org/litedown/#sec:yaml-syntax for its specifications.

Usage

taml_load(x, envir = parent.frame())

taml_file(path)

taml_save(x, path = NULL, indent = " ")

Value

taml_load() and taml_file() return a list; if path = NULL, taml_save() returns a character vector, otherwise the vector is written to the file specified by the path.

Arguments

x

For taml_load(), a character vector of the YAML content. For taml_save(), a list to be converted to YAML.

envir

The environment in which R expressions in YAML are evaluated. To disable the evaluation, use envir = FALSE.

path

A file path to read from or write to.

indent

A character string to indent sub-lists by one level.

Examples

Run this code
(res = taml_load("a: 1"))
taml_save(res)

(res = taml_load("a: 1\nb: \"foo\"\nc: null"))
taml_save(res)

(res = taml_load("a:\n  b: false\n  c: true\n  d: 1.234\ne: bar"))
taml_save(res)
taml_save(res, indent = "\t")

taml_load("a: !expr paste(1:10, collapse = \", \")")
taml_load("a: [1, 3, 4, 2]")
taml_load("a: [1, \"abc\", 4, 2]")
taml_load("a: [\"foo\", \"bar\"]")
taml_load("a: [true, false, true]")
# the other form of array is not supported
taml_load("a:\n  - b\n  - c")
# and you must use the yaml package
if (loadable("yaml")) yaml_load("a:\n  - b\n  - c")

Run the code above in your browser using DataLab