Skip to content

Commit

Permalink
with a4c97d8, when rendering multiple output formats, each format is …
Browse files Browse the repository at this point in the history
…rendered in a new session, so we no longer need clean_envir = TRUE
  • Loading branch information
yihui committed Sep 10, 2020
1 parent 532eefb commit 06c32c0
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions inst/examples/05-editing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ The argument `...` is passed to the output format function. Arguments `clean` an

The output directory of the book can be specified via the `output_dir` argument. By default, the book is generated to the `_book` directory. This can also be changed via the `output_dir` field in the configuration file `_bookdown.yml`, so that you do not have to specify it multiple times for rendering a book to multiple output formats. The `new_session` argument has been explained in Section \@ref(new-session). When you set `preview = TRUE`, only the Rmd files specified in the `input` argument are rendered, which can be convenient when previewing a certain chapter, since you do not recompile the whole book, but when publishing a book, this argument should certainly be set to `FALSE`.

When you render the book to multiple formats in the same R session, you need to be careful because the next format may have access to R objects created from the previous format. You are recommended to render the book with a clean environment for each output format. The argument `clean_envir` can be used to clean all objects in the environment specified by `envir`. By default, it is `TRUE` for non-interactive R sessions (e.g., in batch mode). Note that even `clean_envir = TRUE` does not really guarantee the R session is clean. For example, packages loaded when rendering the previous format will remain in the session for the next output format. To make sure each format is rendered in a completely clean R session, you have to actually launch a new R session to build each format, e.g., use the command line

```sh
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')"
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::pdf_book')"
```

A number of output files will be generated by `render_book()`. Sometimes you may want to clean up the book directory and start all over again, e.g., remove the figure and cache files that were generated automatically from **knitr**. The function `clean_book()` was designed for this purpose. By default, it tells you which output files you can possibly delete. If you have looked at this list of files, and are sure no files were mistakenly identified as output files (you certainly do not want to delete an input file that you created by hand), you can delete all of them using `bookdown::clean_book(TRUE)`. Since deleting files is a relatively dangerous operation, we would recommend that you maintain your book through version control tools such as GIT, or a service that supports backup and restoration, so you will not lose certain files forever if you delete them by mistake.

## Preview a chapter
Expand Down

0 comments on commit 06c32c0

Please sign in to comment.