如何在RStudio中构建一本不在顶级目录中的bookdown书?

How to build a bookdown book that is not in the top-level directory in RStudio?

bookdown docs设置好_bookdown.yml后说的,

Then you can click the Build Book button in the Build pane in RStudio to compile the Rmd files into a book

我在 RStudio 中看不到 "Build Book" 按钮,即使在重新启动后也是如此。

> packageVersion('bookdown')
[1] ‘0.18’

这是我的 _bookdown.yml:

rmd_files: ["one.Rmd", "two.Rmd", "three.Rmd"]
site: "bookdown::bookdown_site"
output:
  bookdown::gitbook:
    lib_dir: "book_assets"
  bookdown::pdf_book:
    keep_tex: yes
delete_merged_file: true

不知道是不是因为我的_bookdown.yml和我的.Rmd文件不在顶级目录下。我想每周制作一本书,所以每本书都有一个子目录。我用的是同一个顶层工程,所以书之间可以共享代码。

因此,如果我对子目录问题的看法是正确的:如何在 RStudio 中构建一本不在顶级目录中的记事簿?

否则,还有什么我应该检查的吗?

编辑:我只是在开发一个函数来构建这本书,比如:

make_book <- function(subdir) {
  setwd(paste0('dir/',subdir))
  # note: input doesn't matter, because config_file will have the book
  bookdown::render_book(input='_bookdown.yml',
                        config_file='_bookdown.yml')
  setwd(here::here())
}

我建议保留这个函数的想法。 改用这个:

make_book <- function(subdir) { 

origwd <- setwd(file.path('dir', subdir))
on.exit(setwd(origwd))
 bookdown::render_book(input='_bookdown.yml', config_file='_bookdown.yml')
}