References

1 Creating a book with bookdown

install.packages("bookdown")

In RStudio: File > New Project > New Directory > Book project using bookdown

  • Specify directory name: example-book2
  • Subdirectory: C:/
  • HTML book format: gitbook

Then click Build or execute rmarkdown::render_site(encoding = 'UTF-8')

Each chapter is an R Markdown file (extension .Rmd) and starts with the chapter title using the first-level heading (# Chapter Title). By default, bookdown merges all .Rmd files by the order of filenames.

index.Rmd will be treated as the first file when merging all files.

index.Rmd contains the YAML header and the contents of the homepage.

Files that start with _ are skipped.

This behavior can be overidden in the configuration file _bookdown.yml. More details are given here https://bookdown.org/yihui/bookdown/usage.html

Output formats: https://bookdown.org/yihui/bookdown/output-formats.html

2 Uploading book to GitHub Pages

https://bookdown.org/yihui/bookdown/github.html

2.1 Output directory /docs

Set the output directory of your book to be /docs by adding output_dir: "docs" to the configuration file _bookdown.yml.

_bookdown.yml

delete_merged_file: true
output_dir: "docs"
language:
  ui:
    chapter_name: "Chapter "

2.2 Create a repository in GitHub

In GitHub, create a repository with name example-book

Copy SSH git@github.com:Paula-Moraga/example-book.git

2.3 Create project in RStudio

In RStudio, File > New Project > Version Control > Git. Copy repository URL.

  • Repository URL: git@github.com:Paula-Moraga/example-book.git
  • Project directory name: example-book

Copy contents example-book2 to example-book.

Close RStudio and open example-book.Rproj

Build Book

2.4 Push book to GitHub

In Terminal

git status
git add .
git commit -m "initial commit"
git push

2.5 GitHub Pages

In GitHub, go to Settings, Pages, select master, select /docs, and click on Save.

Your site is ready to be published at http://www.paulamoraga.com/example-book/