Learn R Programming

yaml12 (version 0.1.0)

format_yaml: Format or write R objects as YAML 1.2.

Description

format_yaml() returns YAML as a character string. write_yaml() writes a YAML stream to a file or stdout and always emits document start (---) markers and a final end (...) marker. Both functions honor a yaml_tag attribute on values (see examples).

Usage

format_yaml(value, multi = FALSE)

write_yaml(value, path = NULL, multi = FALSE)

Value

format_yaml() returns a scalar character string containing YAML. write_yaml() invisibly returns value.

Arguments

value

Any R object composed of lists, atomic vectors, and scalars.

multi

When TRUE, treat value as a list of YAML documents and encode a stream.

path

Scalar string file path to write YAML to when using write_yaml(). When NULL (the default), write to R's standard output connection.

Examples

Run this code
cat(format_yaml(list(foo = 1, bar = list(TRUE, NA))))

docs <- list("first", "second")
cat(format_yaml(docs, multi = TRUE))

tagged <- structure("1 + 1", yaml_tag = "!expr")
cat(tagged_yaml <- format_yaml(tagged), "\n")

dput(parse_yaml(tagged_yaml))


write_yaml(list(foo = 1, bar = list(2, "baz")))

write_yaml(list("foo", "bar"), multi = TRUE)

tagged <- structure("1 + 1", yaml_tag = "!expr")
write_yaml(tagged)

Run the code above in your browser using DataLab