Losing R-Markdown title when automating knitting

1k views Asked by At

I am trying to automate the creation of a bunch of Rmd files that I have been tediously knitting manually with R-Studio - using the "Knit HTML" button that is enabled when you edit an Rmd file. However if I use the knit2html command from a script, it loses the title. This is apparently explained as by design in this post:

Title not showing on R Markdown with knitr when rendering markdown file

However it does not explain how R-Studio manages to generate the title in the html files it produces - it must be possible somehow, right? I have been trying with this test.Rmd R-markdown.

---
title: "My Title"
author: "Joe Programmer"
date: "Thursday, 10 June 2015"
output: html_document
---

Just read the instructions.

And getting this when I use the Knit HTML button below

enter image description here

But this when I knit from the console with knit2html()

enter image description here

How can I get my code to work the way R-Studio does?

1

There are 1 answers

1
hrbrmstr On BEST ANSWER

RStudio answers that here. You can see the template they use at this gist, and if you look at the markdown generation pane you'll see that eventually a wicked long pandoc call is made:

/usr/local/bin/pandoc forso.utf8.md 
  --to html 
  --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures 
  --output forso.html 
  --smart 
  --email-obfuscation none 
  --self-contained 
  --standalone 
  --section-divs 
  --template /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rmarkdown/rmd/h/default.html 
  --variable 'theme:bootstrap' 
  --include-in-header /var/folders/2d/r3dsy9j17lqcctq5k0hmmg040000gn/T//RtmptThd32/rmarkdown-str16cec488b85bd.html 
  --mathjax --variable 'mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' 
  --no-highlight 
  --variable highlightjs=/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rmarkdown/rmd/h/highlight 

Dig into that similar output on your own system to see what else you need to pass to your own custom renderer to get the desired output.