This function tweaks the behavior of as.yaml to return a string which can immediately be used as an R Markdown YAML header. It's designed to accept both deeply nested lists and simpler list formats to make reasoning about your header easier.

create_yaml_header(
  ...,
  line.sep = c("\n", "\r\n", "\r"),
  indent = 2,
  unicode = TRUE,
  indent.mapping.sequence = FALSE,
  handlers = NULL
)

Arguments

...

A set of objects that will be combined into the YAML header. Objects may be provided as lists (the structure list("outputs" = "html_document") translates to outputs: html_document) or as single-item named vectors (passing "title" = "My Report" to ... will translate to title: "My Report").

line.sep, indent, unicode, indent.mapping.sequence, handlers

Additional arguments to be passed to as.yaml

Value

Returns a string formatted for use as an R Markdown YAML header.

See also

Other manipulation functions: heddle(), make_template(), provide_parameters(), use_parameters()

Examples

headerContent <- list(
  "title" = "Testing YAML",
  "author" = "Mike Mahoney",
  "output" = list(
    "flexdashboard::flex_dashboard" = list(
      "vertical_layout" = "fill",
      "orientation" = "rows",
      "css" = "bootstrap.css"
    )
  )
)
create_yaml_header(headerContent)
#> [1] "---\ntitle: Testing YAML\nauthor: Mike Mahoney\noutput:\n  flexdashboard::flex_dashboard:\n    vertical_layout: fill\n    orientation: rows\n    css: bootstrap.css\n---\n"
create_yaml_header(
  "title" = "testing",
  "params" = list("data" = "NA"),
  list("author" = "Mike Mahoney")
)
#> [1] "---\ntitle: testing\nparams:\n  data: NA\nauthor: Mike Mahoney\n---\n"