Skip to content

Document advanced render workflow with IDE when Building book #1139

@cderv

Description

@cderv

I don't think this is documented anywhere and it can be surprising
https://community.rstudio.com/t/r-studio-build-book-for-bookmark-fail-if-makefile-exists/102023

What is possible is currently comment only

bookdown/R/site.R

Lines 28 to 30 in 36f4dca

# Custom render function. bookdown rendering is more complex than
# for most formats and as a result uses a custom R script (_render.R)
# or Makefile to define what's required to render the book.

bookdown/R/site.R

Lines 65 to 66 in 36f4dca

# render the book via _render.R or Makefile, or fallback to render_book()
render_book_script = function(output_format = NULL, envir = globalenv(), quiet = TRUE) {

We should add in the book or in ?bookdown::bookdown_site so that it is explained:

  • When build book in the IDE:
    • _render.R is sourced to build the book if it exists
    • if not, make is called if Makefile file exists in the book project
    • if not, bookdown::render_book("index.Rmd", ...) is used

This allows advanced workflows when creating a book in combination with _output.yaml containing several formats.
Which is mentioned in the book in two places:

Once all formats are specified in `_output.yml`, it is easy to write an R or Shell script or Makefile to compile the book. Below is a simple example of using a Shell script to compile a book to HTML (with the GitBook style) and PDF:

After you have set up GIT, the rest of work can be automated via a script (Shell, R, or Makefile, depending on your preference). Basically, you compile the book to HTML, then run git commands to push the files to GitHub, but you probably do not want to do this over and over again manually and locally. It can be very handy to automate the publishing process completely on the cloud, so once it is set up correctly, all you have to do next is write the book and push the Rmd source files to GitHub, and your book will always be automatically built and published from the server side.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions