Specify Constant YAML Functions in template.yaml file of Rmarkdown Template

I have created an Rmarkdown LaTeX Template that other students will use in the future. My goal is to minimize the skeleton.rmd YAML as much as I can.

Here is what my current YAML looks like:

---
title: "Homework Title"
date: "`r format(Sys.time(), '%B %d, %Y')`"
author: "Your Name"
class: "Course Code"
professor: "Professor Name"
due: "date"
topic: "Chapter X.x"
misc: "X Points Possible"
output: HomeworkBYUI::homework_pdf
---

I would like to abstract away output: HomeworkBYUI::homework_pdf if at all possible. My thoughts are to put it in the template.yaml file that is specified in my package folder path.

Could I also abstract away date:?

Essentially what I'm looking for is a Shared Options answer using a _output.yaml but for a Template package.

Once, I used Rmarkdown template custom format for this purpose.

Basically, I made a wrapper ,like in the example, of html_document fixing some of the parameter directly in the function, and exposing some with default or not.

When this format was used, you only need to specify in yaml those arguments which were in the function. All the other yaml parameters are taken care of inside the function.

With this I think you can even abstract date if it is inside the function.

Problem is for you: it does not really abstract the custom function...

However, did you try this approach to abstract some parameters and even fix default ?

Example from Rmarkdown website:

quarterly_report <- function(toc = TRUE) {

  # get the locations of resource files located within the package
  css <- system.file("reports/styles.css", package = "mypackage")
  header <- system.file("reports/quarterly/header.html", package = "mypackage")

  # call the base html_document function
  rmarkdown::html_document(toc = toc,
                           fig_width = 6.5,
                           fig_height = 4,
                           theme = NULL,
                           css = css,
                           includes = includes(before_body = header))
}

fig_width, fig_height, theme, css, and includes are set once inside the function and can't be change by a yaml in the Rmd document. It is not customisable by the user for this custom format (and it is the purpose)

Only argument that can be change is the toc, and it is set to TRUE by default, if none is provided

---
title: "Untitled"
output: mypackage::quarterly_report
---

There is also a vignette about this.

Thanks for the response, but yes what I already have completed is what you posted to me. I've abstracted away several document level settings and now what's left are options that I want the user to directly be able to customize I was just hoping I would be able to remove the custom function so as to further simplify the YAML for users.

1 Like