knitr + Rmd automate Date on title slide

html, knitr, pandoc, r

Solution

This turns out to be a Pandoc problem, which was hidden so very deep that it took me quite a while to realize what was wrong there. The problem is that you have spaces in the end of the first two lines. In Pandoc's markdown, two or more spaces in the end of a line means a line break. Everything works if you remove the white spaces in the first two lines, e.g.

% Title
% Name
% `r as.character(format(Sys.Date(), format="%B %d, %Y"))`

{r setup, include=FALSE} # set global chunk options opts_chunk$set(cache=TRUE) library(knitr)

`

Problem

I would like to have a template of an .Rmd file that I use to make html5 slides. Generally the beginning part of the template is: ``` % Title % Name % Date ``` I'd like to automatically fill in the Date so the template is always ready to go. (after running Pandoc as seen here) This works but is hacky in that now date and name show in main html file (before html5 processing) because I had to remove the `%` before these elements: ```` % Title Name `r as.character(format(Sys.Date(), format="%B %d, %Y"))` ```{r setup, include=FALSE} # set global chunk options opts_chunk$set(cache=TRUE) library(knitr) ``` ```` Maybe there's a non R, more html, fix.

Original source