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

三世轮回 提交于 2019-12-06 04:56:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27852587/title-not-showing-on-r-markdown-with-knitr-when-rendering-markdown-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!