r - 使用 _site.yml 文件时渲染 Xaringan Rmd
问题描述
我有一个包含三个文件的网站。
_site.yml
name: Website
navbar:
title: Website
right:
- text: Home
- text: Info
output:
html_document:
theme: flatly
highlight: tango
索引.Rmd
---
title: Welcome
output:
html_document:
theme: united
highlight: textmate
---
This is the index.
测试.Rmd
---
title: Test
output:
html_document:
theme: united
highlight: textmate
---
This is the test file.
```{r}
2+2
```
如果我运行rmarkdown::render("test.Rmd")
,我会得到一个包含网站标题的 HTML。这类似于输出运行rmarkdown::render_site()
。
如果我删除_site.yml
文件并运行相同的命令,我会得到常规的 HTML 输出:
所以,render()
必须在使用_site.yml
时使用。这可以禁用吗?即使_site.yml
文件存在,我也想创建一个常规的 HTML 输出。当我有 xaringan 演示文稿并且我不希望它们与网站标题一起呈现时,这尤其是一个问题。
解决方案
我认为没有办法在 中禁用它rmarkdown
,但您可以尝试以下解决方法暂时重命名它,然后再将其重新命名:
render_without_site_yml <- function(input, ...) {
dir <- dirname(input)
site_yml <- file.path(dir, "_site.yml")
if (file.exists(site_yml)) {
newname <- file.path(dir, "_site.yml.save")
if (file.exists(newname))
stop("'_site.yml.save' exists!")
file.rename(site_yml, newname)
on.exit(file.rename(newname, site_yml))
}
rmarkdown::render(input, ...)
}
推荐阅读
- jquery - 无法提供固定位置以在下拉列表中添加新选项
- mysql - 如何在不使用子查询的情况下编写查询?
- c# - SSIS 脚本任务:从 datatable1 选择到 datatable2
- python - 有没有更好的方法来抓取这些数据?
- reactjs - 如何在 React 360 中加载用户选择的本地图像
- mysql - 如何将一列复制到另一列与同一张表上的mysql中的数据?
- angular - Angular 7 错误 RangeError:超出最大调用堆栈大小
- c# - MVC 逻辑 - 如何将静态全局变量拉到我的视图中?
- ios - 如何为按钮点击编写单元测试?
- c# - 是否可以跳过一行