gpt4 book ai didi

Rmarkdown : different output folders, 共享库

转载 作者:行者123 更新时间:2023-12-02 10:28:22 24 4
gpt4 key购买 nike

我有一个 .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")
}

从渲染参数可以看出,html 输出应该进入列表中每个值的单独文件夹,在上面的示例中:文件夹:“Monkey”和文件夹“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')`"
---

但是:当我调用渲染函数时,我收到此错误:

Error in relativeTo(basepath, dir) :

The path C:/Users/ac/Dropbox/2014_07_WIP/pub/libs/jquery-1.11.0 does not appear to be a descendant of C:/Users/ac/Dropbox/2014_07_WIP/Monkey/

所以我猜 rmarkdwown::render 首先创建相对于 Rmd 文件的 lib 目录,但期望这些文件相对于输出文件放置。

如何解决这个问题,以便我可以在一个文件夹中拥有一组常见的 Rmd 输入文件,并在不同的文件夹中拥有输出,同时共享一个公共(public)库?

我试图在前面放置这样的东西。

---
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')`"
---

我得到了这个错误:

  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

最佳答案

我通过在渲染调用中传递一些前面的内容解决了我眼前的问题:

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")

请注意,lib_dir 必须相对于 Rmd 文件,css 必须相对于输出文件。

出于某种原因 - 无论我使用 paste 还是 file.path(fsep="/", ...) css > 输出文件中的路径与 Windows 分隔符(“\”)链接 - 因此在例如火狐浏览器。

关于Rmarkdown : different output folders, 共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24610740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com