3

I'd like to generate a template for rmarkdown that automatically inserts static values into the template. Specifically, I'd like to insert the current date (formatted as DD Month YYYY) into the header and text and the current user's name into the header.

---
title: "Template Title"
author: "Your Name"
date: "The Date"
output:
  pdf_document:
    toc: yes
---

# Version History

* The Date: Initial version

Where it currently says Your Name and The Date, I'd like those to be replaced with the current username and formatted date (as occurs when creating a new rmarkdown document in RStudio).

Edit: As I'm looking for static and not dynamic values, this question differs from YAML current date in rmarkdown.

Bill Denney
  • 766
  • 1
  • 6
  • 21
  • is the username coming from RStudio server? – Nate Dec 08 '18 at 17:52
  • I like the idea, but from my understanding, the insertion of static date and title values is done within the RStudio code. You can see the stock R Markdown template [here](https://github.com/rstudio/rstudio/blob/master/src/cpp/session/resources/templates/r_markdown_v2.Rmd). You could consider using extracting the current date within the YAML as [here](https://stackoverflow.com/questions/23449319/yaml-current-date-in-rmarkdown)? – Michael Harper Dec 09 '18 at 13:43
  • 1
    @Nate, I'm not sure how RStudio does it (that's what I'm trying to find out). I'd be OK with the username coming from the system (Linux, Windows, or Mac) or RStudio. But, I specifically need it to be static not a dynamic system query (so, a call to `whoami` in Linux isn't what I need). – Bill Denney Dec 09 '18 at 14:14
  • @MichaelHarper, Do you have a verification that the static date is coming from within RStudio (if so, please post that as the answer and I'll give credit)? That is the behavior I want to replicate. For my template needs, the current, dynamic date as described in the other answer isn't what I'm looking for. – Bill Denney Dec 09 '18 at 14:16
  • 1
    Struggling to find definitive proof, but I can't see anything within the R Markdown package which would be capable of directly doing this. I think you could get a solution working whereby you use the `writeLines` function to add this static data to your file, but this probably won't be done in the same way that RStudio does it. – Michael Harper Dec 09 '18 at 14:29

0 Answers0