Skip to contents

[Experimental] parse a named list to the Rmd yaml header, so the developer gets automatically tabulated Rmd yaml header. Only a non nested (flat) list will be processed, where as a nested list is directly processed with the yaml::as.yaml function. All Rmd yaml header fields from the vector are supported, c("author", "date", "title", "subtitle", "abstract", "keywords", "subject", "description", "category", "lang"). Moreover all outputfield types in the rmarkdown package and their arguments are supported.

Usage

as_yaml_auto(
  input_list,
  as_header = TRUE,
  convert_logi = TRUE,
  multi_output = FALSE,
  silent = FALSE
)

Arguments

input_list

named list non nested with slots names and their values compatible with Rmd yaml header.

as_header

logical optionally wrap with result with the internal md_header(), default TRUE.

convert_logi

logical convert a character values to logical, if they are recognized as quoted yaml logical values , default TRUE.

multi_output

logical multi output slots in the input argument, default FALSE.

silent

logical suppress messages and warnings, default FALSE.

Value

character with rmd_yaml_header class, result of yaml::as.yaml, optionally wrapped with internal md_header().

Examples

# nested so using yaml::as.yaml directly
as_yaml_auto(
  list(author = "", output = list(pdf_document = list(toc = TRUE)))
)
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#> ---

# auto parsing for a flat list, like shiny input
input <- list(author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE)
as_yaml_auto(input)
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: yes
#> ---

as_yaml_auto(list(author = "", output = "pdf_document", toc = TRUE, keep_tex = "TRUE"))
#> The 'TRUE' value should be a logical, so it is automatically converted.
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: yes
#> ---

as_yaml_auto(list(
  author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE,
  wrong = 2
))
#> Warning: Not recognized and skipped arguments: wrong
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: yes
#> ---

as_yaml_auto(list(author = "", output = "pdf_document", toc = TRUE, keep_tex = 2),
  silent = TRUE
)
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: 2.0
#> ---

input <- list(author = "", output = "pdf_document", toc = TRUE, keep_tex = "True")
as_yaml_auto(input)
#> The 'True' value should be a logical, so it is automatically converted.
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: yes
#> ---
as_yaml_auto(input, convert_logi = TRUE, silent = TRUE)
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: yes
#> ---
as_yaml_auto(input, silent = TRUE)
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: yes
#> ---
as_yaml_auto(input, convert_logi = FALSE, silent = TRUE)
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: 'True'
#> ---

as_yaml_auto(
  list(
    author = "", output = "pdf_document",
    output = "html_document", toc = TRUE, keep_tex = TRUE
  ),
  multi_output = TRUE
)
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: yes
#>   html_document:
#>     toc: yes
#> ---
as_yaml_auto(
  list(
    author = "", output = "pdf_document",
    output = "html_document", toc = "True", keep_tex = TRUE
  ),
  multi_output = TRUE
)
#> The 'True' value should be a logical, so it is automatically converted.
#> ---
#> author: ''
#> output:
#>   pdf_document:
#>     toc: yes
#>     keep_tex: yes
#>   html_document:
#>     toc: yes
#> ---