gpt4 book ai didi

r - bookdown中如何使用Rscript命令行工具建书

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

由于交叉引用功能,我使用 bookdown 而不是 rmarkdown 来生成动态报告。我有多个报告要生成,所以我起草了一个 R 脚本来在 for 循环中调用 bookdown:render_book 来生成所有报告.不幸的是,它出错了。为简单起见,我构建了一个最小示例:

要呈现的 bookdown 文件(另存为 index.Rmd):

---
title: "test"
output: html_document
---

```{r test}
ext_var
```

build.R:

ext_var <- "test.html"
bookdown::render_book("index.Rmd", output_file = ext_var) # it will call `rmarkdown::render`.

当使用如下命令:Rscript build.R时,会产生如下错误信息:

$ Rscript build.R
Error in rmarkdown::render(main, output_format, ..., clean = clean, envir = envir, :
'ext_var'
Calls: <Anonymous> -> render_cur_session -> <Anonymous>
Please delete _main.Rmd after you finish debugging the error.

然后我将 build.R 改为使用 rmarkdown::render:

ext_var <- "test.html"
rmarkdown::render("index.Rmd", output_file = ext_var)

不会有任何错误。所以我想可能有一些问题需要解决。

sessionInfo():

R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] RevoUtils_11.0.0 RevoUtilsMath_11.0.0

loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 bookdown_0.7 digest_0.6.15 rprojroot_1.3-2 backports_1.1.2
[6] magrittr_1.5 evaluate_0.10.1 stringi_1.1.7 rstudioapi_0.7 rmarkdown_1.10
[11] tools_3.5.0 stringr_1.3.1 xfun_0.1 yaml_2.1.19 compiler_3.5.0
[16] htmltools_0.3.6 knitr_1.20

同时提交 an issue #592rstudio/bookdown 存储库中。

最佳答案

作为you have discovered by yourself ,问题是由您的情况下的默认 render_book(clean_envir = TRUE) 引起的。

但是,还请注意 bookdown::render_book() 不应该与 bookdown 包中的输出格式以外的输出格式一起使用。换句话说,您不应期望 html_document 格式与 render_book 一起使用。如果需要交叉引用功能,请使用bookdown包中名称以2结尾的输出格式(如bookdown::html_document2 ),这些格式被设计为与 rmarkdown::render() 一起使用。参见 Section 3.4在 bookdown 书中获取更多信息。

关于r - bookdown中如何使用Rscript命令行工具建书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50888871/

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