Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 461
user3874377 Avatar asked Jan 09 '15 01:01

user3874377


People also ask

Can I make an HTML file from a R Markdown file?

Be able to produce (‘knit’) an HTML file from a R Markdown file. Know how to modify chunk options to change the output in your HTML file. You will need the most current version of R and, preferably, RStudio loaded on your computer to complete this tutorial.

How do I view my knitting progress in R Markdown?

When you click the Knit HTML button, a window will open in your console titled R Markdown. This pane shows the knitting progress. The output (HTML in this case) file will automatically be saved in the current working directory.

How do I use knit HTML in RStudio?

Source: National Ecological Observatory Network (NEON) To knit in RStudio, click the knit pull down button. You want to use the knit HTML for this lesson. When you click the Knit HTML button, a window will open in your console titled R Markdown. This pane shows the knitting progress.

How to render a document in Rmarkdown with empty environment?

The latter ( envir) offers a way to render a document with the guarantee of an empty new environment when you call rmarkdown::render (..., envir = new.env ()), so objects created in your code chunks will stay inside this environment, without polluting your current global environment.


1 Answers

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.

like image 172
Yihui Xie Avatar answered Sep 24 '22 13:09

Yihui Xie