user3874377
user3874377

Reputation: 255

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

I am trying to convert a .Rmd file to .md (output: md_document), but the title does not show up on the rendered file.

The title does show up when I try to render the same file as an .html file (output: html_document).

Title shows up on rendered document:

---
title: "Test"
output: html_document
---

```{r}

head(cars)
```


Title does not show up on rendered document:

---
title: "Test"
output: md_document
---

```{r}

head(cars)
```


rmarkdown::render(my_file)

Any ideas why?

I am using RStudio 0.98.1091 and R 3.1.2 on a Mac 10.9.5.


The code in between -- gets interpreted, as my references are rendered with the following piece of code:

---
title: "Test"
output: md_document
bibliography: ~/mybib.bib
---

This is a test where I cite [@post1, @post2]


The interesting thing is that when I ask for both the html and md files to be generated, the title shows up on the .md file:

---
title: "Test"
output:
  html_document:
    keep_md: yes
---

Shouldn't the output of keep_md: yes be the same as output: md_document?

Upvotes: 5

Views: 3495

Answers (1)

Yihui Xie
Yihui Xie

Reputation: 30184

Markdown does not have such a concept as "title". HTML has the <title> tag (and Pandoc also puts the title in <h1> for the HTML output from Markdown so you can see it from the HTML body), and LaTeX has the \title{} command. It is not unexpected to me that the YAML metadata (including the title info) is not reflected in the Markdown output.

Upvotes: 5

Related Questions