通过.Rmd在标头中插入标签 [英] Insert tags in header via .Rmd
问题描述
我正在使用Rstudio创建Rmd报告,并且我希望能够在将Rmd编织到html中时将meta标签插入到<head>
中.
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.
从编织器选项上的文档中,我认为我可以设置标题选项以在之间插入文本<head>
标记如下:
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?
推荐答案
您在yaml标头中使用一行来读取外部.html文件,其中标头代码段为
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.
这里是对上面链接的稍作修改,包括您的代码,并包括了在.Rmd文件中创建外部.html标头文本的选项,该选项不是必需的:
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)
```
这篇关于通过.Rmd在标头中插入标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!