在一级目录中构建 bookdown 书

Building `bookdown` book in 1-up level directory

背景 -
我的整个 bookdown 项目都在 _source 目录中,我想把编译好的书放在 docs 的 1-up 目录中。 完整路径是 - "C:/Users/kbc/project1/docs/_source"

工作解决方案-
我可以通过使用 -
_bookdown.yml 中硬编码输出目录来做到这一点 output_dir: 'C:/Users/kbc/project1/docs'

问题-
但是,我想通过使用 here::here() 检索当前位置并使用 -
去除最后的 /_source 部分来灵活处理路径 output_dir: stringr::str_remove_all(here::here(), "/_source").

但是构建失败并出现以下错误 -

Error in file(con, "w") : cannot open the connection
Calls: <Anonymous> ... write_ref_keys -> <Anonymous> -> writeLines -> file
In addition: There were 32 warnings (use warnings() to see them)
Execution halted

Exited with status 1.

为什么 output_dir: 接受硬编码的字符数组,而不是函数中的字符数组?我可以为灵活的方法做些什么?

也许您可以只使用 output_dir: ../(尾部斜杠是可选的)。两个点 ../ 正是您要查找的内容,您不需要依赖两个额外的包(此处stringr).

也就是说,我不推荐这种目录结构,因为源代码包含在输出目录中。我建议将源代码与输出目录分开,以便输出目录包含纯输出,否则在清理输出目录时可能会不小心删除完整源代码(例如 运行 bookdown::clean_book())。可以考虑将源放在C:/Users/kbc/project1/Rmd下,设置output_dir: ../docs/.