pzhaonet / bookdownplus

The easiest way to use R package bookdown for writing varied types of books and documents
MIT License
252 stars 31 forks source link
bookdown cran latex r rstudio thesis writing-articles

CRAN downloads

Introduction

The package bookdownplus (Zhao 2017a) is an extension of R bookdown (Xie 2016). It is a collection of multiple templates on the basis of LaTeX, which are tailored so that I can work happily under the umbrella of bookdown. bookdownplus helps you write academic journal articles, guitar books, chemical equations, mails, calendars, and diaries.

Features

bookdown features the collaboration of many fantastic tools. However, an R beginner might be confused or depressed in struggling in the flood of LaTeX, YAML, Markdown, Pandoc, etc. It would be a pity if users stop their steps at the door and give up the courage of entering the wonderful world of bookdown.

bookdownplus is the easiest shortcut to the world of bookdown. With just one single command users can get a demo book (or multiple demo books) in .pdf or .doc, or even more formats (see the quick start section). bookdownplus extends the features of bookdown, and simplifies the procedure. Users only have to choose a template, clarify the book title and author name, and then focus on writing the text. No need to struggle in YAML and LaTeX.

With bookdownplus users can

The website bookdownplus gallery shows some samples that bookdownplus provides.

Quick start

Preparation

  1. Install R, RStudio. LaTeX(e.g. MiKTeX or TinyTeX. See the official manual of ‘bookdown’ for details.

  2. Run RStudio. Type the following codes in the top-left panel to install ‘bookdown’ packages:

install.packages('bookdown')

Installation

# the development version from GitHub (recommended)
devtools::install_github("pzhaonet/bookdownplus")
# or the stable version from CRAN
install.package("bookdownplus")

Generate a demo book

Firstly check your working directory (getwd()) and make sure that it is empty. bookdownplus will generate lots of files. An empty folder as a working directory is highly recommended. If you don’t know how to change your working directory with R command, you can use RStudio to create a new project (File – New Project - New Directory – Empty Project) and work always in this project.

Run the following codes:

require(bookdownplus)
bd('ubt')

Now a demo dissertation for the University of Bayreuth is generated in many formats in the _book/ folder in your working directory. Open _book/ubt.pdfor other files so as to get an impression.

Write your own book

bd() is a simplified function for demos. The main function of the bookdownplus package is:

bookdownplus()

with multiple parameters.

For example,

bookdownplus(template = 'ubt', render = TRUE)   

You can see some other files (e.g. index.Rmd, body.Rmd, -bookdownplus.Rproj) and folders. Write your own texts in body.Rmd and revise the author and the book title in index.Rmd. You can use RStudio or any other text editor (but please don’t use Microsoft Word).

After writing some texts, open -bookdownplus.Rproj with RStudio, and press ctrl+shift+b to build your own lovely book.

More outputs

By default, the book is built in a .pdf file and an .md file. From ‘bookdownplus v1.0.3’, users can get more output formats, including word, html and epub. From ‘bookdownplus v1.2.0’, uses can see the available output formats by running:

get_output()

You can specify the more_output argument in the bookdownplus() function:

bookdownplus(more_output = get_output())

Then all the required output files are in _book/ folder.

More templates

By default, the book is built from the ‘ubt’ template. From ‘bookdownplus v1.2.0’, users can see the available templates by running:

get_template()

A template with a name ended with ’_zh’ means that it supports Chinese characters. To list all these Chinese templates, run:

grep('_zh$', get_template()[, 'name'], value = TRUE)

You can specify the template argument in the bookdownplus() function:

bookdownplus(template = get_template()$name[1])

Then all the required output files are in _book/ folder.

Magic trick

Now it is time to witness the miracles. With the following magic trick you will see what bookdownplus can do.

Chinese users can run the following codes, and go and have a coffee break. When you come back, you will get more than 20 demo books generated from available templates, each in .pdf, .doc, .html, and .epub formats, in _book/:

bd()

Non-Chinese users might encounter some errors because their computers do not support Chinese characters in the demo books. Instead, run the following codes, which exclude the Chinese templates and the remote templates:

my_t <- get_template()
my_t <- my_t$name[my_t$location == 'local' & !grepl('_zh$', my_t$name)]
bd(my_t)

Showcase

The website bookdownplus gallery shows some samples that bookdownplus provides.

Share Your Own Templates

bookdownplus provides around 30 templates (Version 1.5.0). If you are willing to contribute your own bookdown templates to bookdownplus, just upload them to the bookdownplus repo. They will be displayed in the bookdownplus gallery automatically once accepted.

From the version 1.5, bookdownplus opens a widest-ever door to contributors. Here is how:

  1. Make sure that your template works successfully with bookdown.

  2. Prepare a folder in your working directory by running:

    bookdownplus::share('your_template_name')

    Follow the instructions in each subfolder and create the required files.

    • (Mandatory) 'your_template_name/demo.zip' is the compressed file from your bookdown project folder.
    • (Optional) 'your_template_name/showcase/' contains the sample files (e.g. pdf, image files). An image file 'cover.png' is recommended, which will be used as the cover image in the gallery.
    • (Optional) You could write a 'your_template/readme.txt' (in markdown syntax), which will be displayed as the text in the gallery.
  3. Upload your template folder 'your_template_name/' in to 'upload/' of the bookdownplus repo.

  4. Add the template information, including the template name, the contributor's name, and a brief introduction, into 'upload/-list.csv'.

  5. Create a Pull Request to bookdownplus.

Wait for the response, and your template will be available in the gallery. Users can get it easily by clicking the ".zip" link in the gallery, or running

bookdownplus("your_template_name")

Recommendations

I have been developing some other packages, which bring more features into ‘bookdown’, such as:

Both of them have been released on CRAN and can be installed via install.packages('mindr') and install.packages('pinyin').

Enjoy your bookdowning!

Updates

To do

License

Copyright 2018 Peng Zhao.

Released under the MIT license.

References

Xie, Yihui. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. https://github.com/rstudio/bookdown.

Zhao, Peng. 2017a. Bookdownplus: Generate Varied Types of Books and Documents with R ’Bookdown’ Package. https://CRAN.R-project.org/package=bookdownplus.

———. 2017b. Mindr: Convert Files Between Markdown or Rmarkdown Files and Mindmaps. https://CRAN.R-project.org/package=mindr.

———. 2017c. Pinyin: Convert Chinese Characters into Pinyin. https://CRAN.R-project.org/package=pinyin.