Skip to content

Commit

Permalink
Improved intermediate cleanup
Browse files Browse the repository at this point in the history
* Save render args in tempdir()
* Pass clean argument to chapter render
* Delete intermediate .md files

Fixes #986
  • Loading branch information
hadley committed Feb 17, 2021
1 parent 7b1312e commit 7ac3032
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

- Added the same CSS as in default Pandoc's template for when a CSL is used (#1045).

- `render_book()` now correctly cleans up intermediate files if a built is interrupted part way through (#986).

## MINOR CHANGES

- `anchor_sections = TRUE` becomes the default for `bookdown::gitbook()`.
Expand Down
5 changes: 3 additions & 2 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ render_cur_session = function(files, main, config, output_format, clean, envir,
render_new_session = function(files, main, config, output_format, clean, envir, ...) {

# save a copy of render arguments in a temp file
render_args = tempfile('render', '.', '.rds')
render_args = tempfile('render', fileext = '.rds')
on.exit(file.remove(render_args), add = TRUE)
saveRDS(
list(output_format = output_format, ..., clean = FALSE, envir = envir),
list(output_format = output_format, ..., clean = clean, envir = envir),
render_args
)
# an RDS file to save all the metadata after compiling each Rmd
Expand All @@ -207,6 +207,7 @@ render_new_session = function(files, main, config, output_format, clean, envir,
add2 = merge_chapter_script(config, 'after')
on.exit(unlink(c(add1, add2)), add = TRUE)
# compile chapters in separate R sessions
on.exit(unlink(with_ext(files, '.md')), add = TRUE)
for (f in files[rerun]) Rscript_render(f, render_args, render_meta, add1, add2)

if (!all(dirname(files_md) == '.'))
Expand Down

0 comments on commit 7ac3032

Please sign in to comment.