And*_*eas 5 yaml r pandoc rstudio r-markdown
我有一个.R文件,其中我为列表中的每个唯一值渲染了许多不同的.Rmd文件。像这样:
for (uddannelse in unique(c("Monkey","Horse"))) {
rmarkdown::render("file1.Rmd", output_dir=file.path(getwd(), uddannelse) ,output_file=paste("file1", uddannelse,".html", sep="_"), encoding="UTF-8")
rmarkdown::render("file2.Rmd", output_dir=file.path(getwd(), uddannelse), output_file=paste("file2", uddannelse,".html", sep="_"), encoding="UTF-8")
}
Run Code Online (Sandbox Code Playgroud)
从render参数可以明显看出,对于上面列表中的每个值,html-output应该进入一个单独的文件夹,在上面的示例中:folder:“ Monkey”和folder“ Horse”。
每个.Rmd文件都具有以下首要事项(文件进入静态html网站,并且需要具有self_contained: false:
---
output:
html_document:
theme: readable
self_contained: false
lib_dir: pub/libs
css: pub/libs/custom_css/custom.css
date: "`r format(Sys.time(), '%d %B, %Y')`"
---
Run Code Online (Sandbox Code Playgroud)
但是:当我调用render函数时,我收到此错误:
relativeTo(basepath,dir)中的错误:
路径C:/Users/ac/Dropbox/2014_07_WIP/pub/libs/jquery-1.11.0似乎不是C:/ Users / ac / Dropbox / 2014_07_WIP / Monkey /
因此,我想第rmarkdwown::render一个创建相对于Rmd文件的lib目录,但是期望这些文件相对于输出文件放置。
如何解决这个问题,以便可以在一个文件夹中拥有一组通用的Rmd输入文件,并在不同的文件夹中具有输出,但共享一个公共的lib?
我试图将这样的东西放在炸锅里。
---
output:
html_document:
theme: readable
self_contained: false
lib_dir: "`r file.path(uddannelse, "libs")`"
css: "`r file.path(uddannelse, "libs", "custom_css", "custom.css")`"
date: "`r format(Sys.time(), '%d %B, %Y')`"
---
Run Code Online (Sandbox Code Playgroud)
我得到了这个错误:
Error in yaml::yaml.load(front_matter) :
Parser error: while parsing a block mapping at line 3, column 5did not find expected key at line 5, column 50
Run Code Online (Sandbox Code Playgroud)
我通过在渲染调用中传递一些前面的内容解决了我眼前的问题:
rmarkdown::render("file1.Rmd",
output_dir=file.path(uddannelse),
output_file=paste("file1", uddannelse,".html", sep="_"),
output_options=list(html_document =
list(self_contained = FALSE,
lib_dir = file.path(uddannelse, "lib"),
css = paste("lib", "custom_css", "custom.css",
sep="/"),
include = list(
after_body = file.path(uddannelse,
"footer_w_index.html")))),
encoding="UTF-8")
Run Code Online (Sandbox Code Playgroud)
请注意,它lib_dir必须相对于Rmd文件并且css必须相对于输出文件。
由于某种原因 - 无论我是否使用paste或输出文件中的file.path(fsep="/", ...)路径css都与 Windows 分隔符(“\”)链接 - 因此在例如 Firefox 中不可用。