【问题标题】:Building `bookdown` book in 1-up level directory在 1-up 级目录中构建 `bookdown` 书
【发布时间】:2021-04-27 09:09:18
【问题描述】:

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

可行的解决方案 -
我可以通过使用 -
output_dir: 'C:/Users/kbc/project1/docs'

_bookdown.yml 中的输出目录进行硬编码来做到这一点

问题 -
但是,我想通过使用 here::here() 来检索当前位置并使用 -
output_dir: stringr::str_remove_all(here::here(), "/_source") 剥离最后一个 /_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: 接受硬编码的字符数组,而不接受来自函数的字符数组?我可以为灵活方法做些什么?

【问题讨论】:

    标签: r stringr bookdown


    【解决方案1】:

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

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

    【讨论】:

    • 感谢@Yihui Xie,提供解决方案。我也喜欢您将源与输出分开的建议。现在,我使用docs-source 作为源代码,docs 作为我在 GitHub 存储库中的代码文档的输出。再次感谢您的帮助。另外,我非常喜欢您的工作,并且非常感谢您对开源项目的承诺。 :)
    猜你喜欢
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 2021-08-10
    • 1970-01-01
    相关资源
    最近更新 更多