问题
I'm using Rstudio to create Rmd reports, and I'd like to be able to insert meta tags into the <head>
when the Rmd is knit into html.
From the documentation on knitr options I thought I could set the header option to insert text between the <head>
tags like so:
```{r}
opts_knit$set(header = "<meta name=\"description\" content=\"this is a description\">")
```
However, nothing seems to be inserted. Am I doing something wrong or is this not possible?
回答1:
You use a line in the yaml header that reads in an external .html file with your header snippet in it as per this link.
Here is a slight modification from the link above including your code and includes the option the creation of the external .html header text in the .Rmd file which is not required:
---
title: "Test"
output:
html_document:
includes:
in_header: header.html
---
```{r setup, include=FALSE, echo=FALSE}
# Create header.html
CON <- file("header.html")
writeLines('<meta name="description" content="this is a description" />', CON)
close(CON)
```
来源:https://stackoverflow.com/questions/19748205/insert-tags-in-header-via-rmd