作者:Yihui Xie
译者:郑宝童
日期:2021.06.02
4.4 Configuration
We have mentioned
rmd_files
in Section 1.3, and there are more (optional) settings you can configure for a book in_bookdown.yml
:
我们已经在1.3节中提到了rmd_files
,并且可以在_bookdown.yml
有更多(可选的)setting为一本书进行配置:
book_filename
: the filename of the main Rmd file, i.e., the Rmd file that is merged from all chapters; by default, it is named_main.Rmd
.delete_merged_file
: whether to delete the main Rmd file after the book is successfully rendered.before_chapter_script
: one or multiple R scripts to be executed before each chapter, e.g., you may want to clear the workspace before compiling each chapter, in which case you can userm(list = ls(all = TRUE))
in the R script.
book_filename
: 主Rmd文件的文件名,即从所有章节合并的Rmd文件;默认情况下,它被命名_main.Rmd
.delete_merged_file
: 是否在成功呈现图书后删除主Rmd文件.before_chapter_script
: 在每个章节之前执行一个或多个R脚本,例如,你可能想在编译每个章节之前清除工作区,在这种情况下,你可以在R脚本中使用rm(list = ls(all = TRUE))
。after_chapter_script
: similar tobefore_chapter_script
, and the R script is executed after each chapter.edit
: a link that collaborators can click to edit the Rmd source document of the current page; this was designed primarily for GitHub repositories, since it is easy to edit arbitrary plain-text files on GitHub even in other people’s repositories (if you do not have write access to the repository, GitHub will automatically fork it and let you submit a pull request after you finish editing the file). This link should have%s
in it, which will be substituted by the actual Rmd filename for each page.history
: similar toedit
, a link to the edit/commit history of the current page.
after_chapter_script
: 类似before_chapter_script
, 相应的R脚本在每个章节之后执行edit
: 协作者可以单击该链接来编辑当前页面的Rmd源文档;这主要是为GitHub库设计的,因为这使得编辑任意在github上(甚至是别人仓库)的纯文本更容易(如果你没有写权限,GitHub将自动fork,让你在完成编辑后提交pull请求)。这个链接应该包含%s
,它将被每个页面的实际Rmd文件名替换。history
: 与edit
类似,它是一个链接,可以为当前页面的历史进行edit/commit。view
: similar toedit
, a link to source code of the current page.rmd_subdir
: whether to search for book source Rmd files in subdirectories (by default, only the root directory is searched). This may be either a boolean (e.g.true
will search for book source Rmd files in the project directory and all subdirectories) or list of paths if you want to search for book source Rmd files in a subset of subdirectories.output_dir
: the output directory of the book (_book
by default); this setting is read and used byrender_book()
.clean
: a vector of files and directories to be cleaned by theclean_book()
function.
view
: 与edit
,类似, 它是一个当前页面源代码的链接。rmd_subdir
: 是否在子目录中搜索书的源Rmd文件(默认只搜索根目录)。它可以是一个布尔值(例如,true
将在项目目录和所有子目录中搜索Rmd源文件),也可以是路径列表(如果你想在子目录的子集中搜索Rmd源文件)。output_dir
: 图书的输出目录(默认为_book
);render_book()
读取并使用该设置。clean
: 要被clean_book()
函数清理的文件和目录的向量
Here is a sample _bookdown.yml
:
book_filename: "my-book.Rmd"
delete_merged_file: true
before_chapter_script: ["script1.R", "script2.R"]
after_chapter_script: "script3.R"
view: https://github.com/rstudio/bookdown-demo/blob/master/%s
edit: https://github.com/rstudio/bookdown-demo/edit/master/%s
output_dir: "book-output"
clean: ["my-book.bbl", "R-packages.bib"]