7 R Markdown and Bookdown
This is an R Markdown and Bookdown document. Here we cover the basics of Rmarkdown, and Bookdown.
7.1 R Markdown
R Markdown provides an authoring framework for data science. You can use a single R Markdown file to both save and execute code, and generate high quality reports that can be shared with an audience.
R Markdown was designed for easier reproducibility, since both the computing code and narratives are in the same document, and results are automatically generated from the source code. R Markdown supports dozens of static and dynamic/interactive output formats.
For tutorials go to website https://rmarkdown.rstudio.com, and watch the videos in the “Get Started” section, which cover the basics of R Markdown.
7.2.1 Build a book
To build all Rmd files into a book, you can call the function bookdown::render_book(). It uses the settings specified in the _output.yml (if it exists). If multiple output formats are specified in it, all formats will be built. If you are using RStudio, this can be done through the Build tab. Open the drop down menu Build Book if you only want to build one format.
7.2.2 Preview a chapter
Building the whole book can be slow when the size of the book is big or your book contains large amounts of computation. We can use the preview_chapter() function in bookdown to only build a single chapter at a time. Equivalently, you can click the Knit button in RStudio.
7.2.3 Serve the book
Instead of running render_book() or preview_chapter() each time you want to view the changes, you can use the function bookdown::serve_book() to start a live preview of the book. Any time a Rmd file is saved, the book will be recompiled automatically, and the preview will be updated to reflect the changes.
7.2.4 Rstudio addins
The bookdown package comes with two addins for RStudio which assist the editing of books:
“Preview Book”: this calls bookdown::serve_book() to compile and serve the book.
“Input LaTeX Math”: provides a text box which allows you to write LaTeX equations, to avoid common errors when typing the raw LaTeX math expressions.
7.3 My Data Example
My data example for this section can be observed through out this bookdown assignment