12.2 Project structure

Below shows the basic structure of a defaultbookdown project:

directory/├──  index.Rmd├── 01-intro.Rmd├── 02-literature.Rmd├── 03-method.Rmd├── 04-application.Rmd├── 05-summary.Rmd├── 06-references.Rmd├── _bookdown.yml├── _output.yml├──  book.bib├──  preamble.tex├──  README.md└──  style.css

As a summary of these files:

  • index.Rmd: This is the only Rmd document to contain a YAML frontmatter as described within Chapter2, and is the first book chapter.

  • Rmd files: A typicalbookdown book contains multiple chapters, and each chapter lives in one separate Rmd file.

  • _bookdown.yml: A configuration file forbookdown.

  • _output.yml: It specifies the formatting of the HTML, LaTeX/PDF, and e-books.

  • preamble.tex andstyle.css: They can be used to adjust the appearance and styles of the book output document(s). Knowledge of LaTeX and/or CSS is required.

These files are explained in greater detail in the following subsections.

12.2.1 Index file

Theindex.Rmd file contains the first chapter and the YAML metadata, e.g.,

---title:"A Minimal Book Example"author:"Yihui Xie"date:"`r Sys.Date()`"site: bookdown::bookdown_sitedocumentclass: bookbibliography:[book.bib, packages.bib]biblio-style: apalikelink-citations:yesdescription:"This is a minimal example of using  the bookdown package to write a book."---

12.2.2 Rmd files

By default, all Rmd files are merged with theindex.Rmd to render the book. The Rmd files must start immediately with the chapter title using the first-level heading, e.g.,# Chapter Title. Note that YAML metadata should not be included in these Rmd files, as it is inherited from theindex.Rmd file.

  • 01-intro.Rmd

    # IntroductionThis chapter is an overview of the methods thatwe propose to solve an **important problem**.
  • 02-literature.Rmd

    # LiteratureHere is a review of existing methods.

By default,bookdown merges all Rmd files by the order of filenames, e.g.,01-intro.Rmd will appear before02-literature.Rmd. Filenames that start with an underscore_ are skipped.

12.2.3_bookdown.yml

The_bookdown.yml file allows you to specify optional settings to build the book. For example, you may want to override the order in which files are merged by including the fieldrmd_files:

rmd_files:["index.Rmd","02-literature.Rmd","01-intro.Rmd"]

12.2.4_output.yml

The_output.yml file is used to specify the book output formats (see Section12.4). Here is a brief example:

bookdown::gitbook:lib_dir: assetssplit_by: sectionconfig:toolbar:position: staticbookdown::pdf_book:keep_tex:yesbookdown::html_book:css: toc.css