Extracts the body from R Markdown file content, stripping a possible YAML metadata block at the beginning.
Usage
strip_yaml_header(rmd, eol = c("LF", "CRLF", "CR", "LFCR"))
Arguments
- rmd
R Markdown file content as a character scalar.
- eol
End of line (EOL) control character sequence. One of
"LF"
for the line feed (LF) character ("\n"
). The standard on Unix and Unix-like systems (Linux, macOS, *BSD, etc.) and the default."CRLF"
for the carriage return + line feed (CR+LF) character sequence ("\r\n"
). The standard on Microsoft Windows, DOS and some other systems."CR"
for the carriage return (CR) character ("\r"
). The standard on classic Mac OS and some other antiquated systems."LFCR"
for the line feed + carriage return (LF+CR) character sequence ("\n\r"
). The standard on RISC OS and some other exotic systems.
Details
Note that for the R Markdown file format, the YAML metadata block must occur at the beginning of the document (and there can be only one). Additional whitespace characters (incl. newlines) before the YAML metadata block are allowed.
See also
Other R Markdown and knitr functions:
build_readme()
,
knitr_table_format()
Examples
rmd <- "
---
output: pal::gitlab_document
---
# A heading
Some prose.
"
rmd |>
stringr::str_split_1("\n") |>
pal::cat_lines()
#>
#> ---
#> output: pal::gitlab_document
#> ---
#>
#> # A heading
#>
#> Some prose.
#>
rmd |>
pal::strip_yaml_header() |>
pal::cat_lines()
#>
#> # A heading
#>
#> Some prose.
#>