Dan Chaltiel
Dan Chaltiel

Reputation: 8494

Set output_file in YAML

When I run render("test.Rmd") with these YAML parameters, the output is still test.docx and not teeeeeeeest.docx:

---
title: "mytitle"
author: "Me, myself and I"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: word_document
output_file: "teeeeeeeest.docx"
---

However, if I set the argument inside the render function (rmarkdown::render("test.Rmd", output_file = "teeeeeeeest.docx")), it works fine.

Is it possible to set the output_file argument inside the YAML header? Else, my purpose is to include the current date in the output file name when knitting with RStudio, how could I do that?

Upvotes: 3

Views: 2356

Answers (1)

Maxime Sainte-Marie
Maxime Sainte-Marie

Reputation: 46

As shown here, it is possible to set the output file name inside the YAML by customizing the knit function within the YAML header. For this, you just need to add a 'knit:' hook in the header, such as in this example:

knit: (function(inputFile, encoding) { 
      rmarkdown::render(inputFile,
                    encoding=encoding, 
                    output_file='new_file_name.html')) })

Upvotes: 3

Related Questions