Create Rmd template that auto-fills in current date just like the default html output format

When I open a new RMarkdown file in RStudio, the YAML header in the default html option conveniently has the date of the file's creation already filled in. For instance:

---
title: "Default HTML output"
author: "Me"
date: "6/19/2018"
output: html_document
---

I would like to incorporate this auto-fill feature into custom html templates in my R pacakge. However I can only find guidance on printing the current date in the knitted report, whereas I want the date auto-filled into the RMarkdown YAML header.

---
title: ""
author: "Me"
date: '`r format(Sys.Date(), "%Y-%B-%d")`'
output: html_document
---

How can I enable the date to be auto-filled into the custom template, just like in the default html option?

As of 2020-08-06 the closest solution I have found is

date: "`r gsub( ' .*$', '', file.info( knitr::current_input() )$ctime)`"

This will pull the creation date from file info, which is about what i wanted.

1 Like

While I don't have an exact answer, would you have a look at this:

This section from the new R Markdown book talks about customizing formats and it may help with having the date variable set to be auto-filled as in the default HTML template.

2 Likes