Welcome back for the 5th day of the #packagecalendar, this time we will take a swing at something as wonderfully complicated as YAML. Malcolm Barrett is trying to make that process easier with ymlthis.
the package is available from CRAN and can be downloaded with
when you normally create a new Rmarkdown document is comes prefilled with some examples and text. At the very beginning of the document you will typically find something that looks like:
--- title: "Elf Report" author: "Kris Kringle" date: "12/5/2019" output: html_document ---
This is called YAML and helps you control document-wide “settings”. With all the benefits of YAML, you still get some downsides. 3 of which are:
And the 3rd one is what makes all of this a pain to work with. YAML will happily ignore what you did if you did 1 space instead of 2 spaces, all without telling you, leaving you scratching your head when you don’t get what you want.
This is where ymlthis comes in!
You will be using
yml() along with
yml_*() functions to compose your YAML chunk.
By loading the package and starting with
yml() you get a basic function header.
## --- ## author: Kris Kringle ## date: '`r format(Sys.Date())`' ## ---
The magic comes later once you start chaining on the
yml() %>% yml_title("Elf Report")
## --- ## author: Kris Kringle ## date: '`r format(Sys.Date())`' ## title: Elf Report ## ---
Here you get the full power of autocompletion since you just have to writ
yml_ and press tab you see the options you have.
This is the workflow you will be using.
No longer do you have to worry about misspellings or indentations!!!
The package and its accompanying documentation include a lot of information about use cases and general YAML information. Find more information in Additional resources. Before I sign off for today, I’ll like to highlight that ymlthis comes with a RStudio Addin if you prefer a more GUI experience.