as.yaml {yaml}R Documentation

Convert an R object into a YAML string

Description

Generic functions to convert R objects into YAML strings

Usage

  ## S3 method for class 'list':
  as.yaml(x, line.sep = c("\n", "\r\n"), indent = 2, pre.indent = 0, omap = FALSE, ...)
  ## S3 method for class 'data.frame':
  as.yaml(x, line.sep = c("\n", "\r\n"), indent = 2, pre.indent = 0, column.major = TRUE, ...)
  ## Default S3 method:
  as.yaml(x, line.sep = c("\n", "\r\n"), indent = 2, pre.indent = 0, ...)

Arguments

x the object to be converted
line.sep the line separator character(s) to use
indent the number of spaces to use for indenting
pre.indent number of indentations to put before each line; see Details
omap determines whether or not to convert a list to a YAML omap; see Details
column.major determines how to convert a data.frame; see Details
... other options to pass to the generic functions

Details

The pre.indent option specifies how many times to indent before each line, rather than how many spaces you want before each line. For example, if you want 3 spaces before each line, you would say: as.yaml(1:10, indent = 3, pre.indent = 1).

If you set the omap option to TRUE, as.yaml will tag the YAML document as an omap, which is an ordered map. This will maintain the order of elements in the list.

The column.major option determines how a data frame is converted. If TRUE, the data frame is converted into a map of sequences where the name of each column is a key. If FALSE, the data frame is converted into a sequence of maps, where each element in the sequence is a row. You'll probably almost always want to leave this as TRUE (which is the default), because using yaml.load on the resulting string returns an object which is much more easily converted into a data frame via as.data.frame.

Value

Returns a YAML string which can be loaded using yaml.load or copied into a file for external use.

Author(s)

Jeremy Stephens <jeremy.stephens@vanderbilt.edu

References

YAML: http://yaml.org YAML omap type: http://yaml.org/type/omap.html

See Also

yaml.load


[Package yaml version 1.1.0 Index]