I would like to include the current date in the output filename when knitting a document using RStudio's knit button. I can somehow change the options of the markdown rendering, but I don't know how. Could anyone point me into the right direction?
You can do this in the console:
library(knitr)
knit("test.Rmd")
knit2html("test.md", output=paste0("test",Sys.Date(),".html")) # Sys.Date() is a string with the current date
Alternate, better version:
rmarkdown::render("test.Rmd",output_file=paste0('test',Sys.Date(),'.html'))
You can directly change the behavior of the RStudio knit button with some code in your document, like this.
To the header, before the output section add this code:
knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, encoding = encoding, output_file = paste0(substr(inputFile,1,nchar(inputFile)-4),Sys.Date(),'.html')) })
The substr(inputFile,1, nchar(inputFile)-4)
strips the ".Rmd" from your Rmd filename.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With