r - 如何将缺少的 YAML 标头信息添加到脚本中的 .rmd R Markdown 文件?
问题描述
我正在开发一个工作流程,我
- 协作处理 Google Doc,然后
- 使用 googledrive 包下载为 .docx,
- 使用 rmarkdown:pandoc_convert() 转换为 .rmd,
- 样式和标志应用和
- 呈现为 .html 和 PDF 以供分发。
当 .rmd 文件没有标题时,我目前正在第 3 步挂断。
pandoc_convert("example.docx", "markdown", output = "out.Rmd")
如何从工作流脚本中的另一个文件注入 YAML?例如这个标题:
---
title: "Title1"
html_document:
number_sections: yes
self_contained: yes
toc: yes
toc_depth: 3
toc_float: yes
---
解决方案
假设您的标题位于header.yaml
. 然后只需读取这两个文件并将它们写成一个:
fulltext <- c(readLines("header.yaml"), readLines("out.Rmd"))
writeLines(fullText, "out2.Rmd")
当然,您也可以将标头放入字符串变量中,而不是从文件中读取它,例如
header <- '---
title: "Title1"
html_document:
number_sections: yes
self_contained: yes
toc: yes
toc_depth: 3
toc_float: yes
---'
fulltext <- c(header, readLines("out.Rmd"))
writeLines(fullText, "out2.Rmd")
推荐阅读
- asp.net-core - 动态cookie认证LoginPath asp.net core 2
- c# - 通过 .Net Core、WPF 和 Xamarin 的多个项目跨解决方案共享图像和类
- javascript - 是否可以从网站以编程方式在用户的 PC 上创建网站快捷方式?
- amazon-web-services - Lambda:执行前和执行后挂钩
- python - 如何将列名转换为行的多索引
- algorithm - 为什么我们需要在 Rabin Karp 算法中每次哈希值相同时检查模式匹配
- oracle - 返回值 PL/SQL 函数
- mysql - 可以有两个自动递增的主键吗?
- python - 如何根据不同列中的值对相似行进行分组
- c# - 是否有消息“抱歉,好像出了点问题”。使用收据卡时在频道 Line 和 Messengers 上