r - 在 R markdown 中的 YAML 标头之前包含 R 块
问题描述
我的 Rmd 文件与它所需的文件位于不同的文件夹中(例如style.css
,、、logo.png
)header.html
我试图将文件夹设置为工作目录,但是在我设置它之前调用了这些文件,因此编织不起作用,因为它找不到文件。
因为它是:
---
title: foo title
author: foo
output:
html_document:
includes:
in_header: header.html
css: style.css
---
```{r setup, include=FALSE, echo=FALSE}
library(knitr)
opts_knit$set(root.dir = "~/path/to/folder/")
```
正如我所希望的那样:
```{r setup, include=FALSE, echo=FALSE}
library(knitr)
opts_knit$set(root.dir = "~/path/to/folder/")
```
---
title: foo title
author: foo
output:
html_document:
includes:
in_header: header.html
css: style.css
---
从我想渲染此报告的 R 脚本中,我使用以下方法调用它:
rmarkdown::render(input = report.rmarkdown.rmd.fpath,
output_file = output.html.report.fpath,
knit_root_dir = report.working.dpath)
但我可以想象在设置 knit_root_dir 的那一刻发生同样的情况。
如果无法在 YAML 标头之前放置一个块,知道如何找到它header.html
吗?style.css
我可以“手动”编写文件路径,但我的 header.html 看起来像:
<div><img src="logo.png" width="200px" align="right"></div>
而且logo.png
无论如何都找不到,对吧?
非常感谢!
解决方案
推荐阅读
- checksum - 如何使用 javascript big endian 格式计算 16 位校验和值
- workflow - AEM 6.5,如何将工作流位置更改为模型/子文件夹
- c# - 如何验证自适应卡片机器人框架v4(瀑布模型)c#中的输入字段
- postgresql - 如何从邻接列表中获取后代数组?
- terraform - 如何在 Terraform Enterprise/Cloud 中运行“terraform state mv”命令?
- c# - 为所有字符提供相等宽度/空间的选项
- sql - 如何指定我的表以将数据以分钟和秒为单位的时间插入列中?
- django - django-redis-cache 创建具有整数值的随机键
- javascript - 在 React 中以嵌套状态重置输入字段(受控组件)
- wordpress - 是否有类似于 get_queried_object() 的函数,它只获取当前存档分类术语但忽略 url 查询参数?