Skip to content

Add date to rmarkdown file output name when clicking "knit" #1153

@jarbet

Description

@jarbet

Describe the bug
I am using rmarkdown within VSCode, and would like to automatically add today's date to the output filename when clicking the 'knit' button. I see that this feature was requested here and added in PR #765, however, I can't get it to work.

To Reproduce
Steps to reproduce the behavior:

  1. Create file test.Rmd that contains the following code:
---
title: "hello world"
knit: (function(input, ...) {
    rmarkdown::render(
      input,
      output_file = paste0(
        xfun::sans_ext(input), '-', Sys.Date(), '.html'
      ),
      envir = globalenv()
    )
  })
---

hello world
  1. Click on Knit > Rmd button:
    image

  2. Unfortunately, the output filename is test.html and does not contain the date:
    image

Note after clicking the knit button, the following command is automatically called (which I suspect is causing the date to be removed from the filename):

rmarkdown::render("test.Rmd", encoding = "UTF-8")

Environment (please complete the following information):

  • OS: macOS but I am using VSCode to connect to a remote server where I am using Rmarkdown/R for analysis
  • VSCode Version: 1.69.1
  • R Version: 4.1.3
  • vscode-R version: v\2.5.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions