Skip to content

Commit

Permalink
fix #1812: when render(run_pandoc = FALSE), exclude the .md output fi…
Browse files Browse the repository at this point in the history
…le and associated figure files from the list of intermediate files, so they won't be cleaned up
  • Loading branch information
yihui committed May 30, 2020
1 parent 7bc6575 commit c860cc2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rmarkdown
Type: Package
Title: Dynamic Documents for R
Version: 2.1.9
Version: 2.1.10
Authors@R: c(
person("JJ", "Allaire", role = "aut", email = "[email protected]"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ rmarkdown 2.2

- For `pandoc_convert()`, when the argument `to = 'pdf'`, it will be changed to `'latex'` internally (thanks, @JohannesFriedrich, #1802).

- `render(run_pandoc = FALSE)` no longer cleans up the Markdown file (typically knitted from Rmd) (thanks, @BrianDiggs, #1812).


rmarkdown 2.1
================================================================================
Expand Down
18 changes: 9 additions & 9 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -780,23 +780,21 @@ render <- function(input,
# the knitr cache is active; clean the figure-* dir instead of the whole
# files_dir if other subdirs are generated by another format and still needed:
# https://github.com/rstudio/rmarkdown/issues/1472 and also #1503
if (output_format$clean_supporting && !dir_exists(cache_dir)) {
intermediates_fig <- if (output_format$clean_supporting && !dir_exists(cache_dir)) {
# unlink does not support / at the end of file path
fig_path <- gsub("/$", "", knitr::opts_chunk$get('fig.path'))

# existing figure folder(s), can be character(0)
# if no figure is generated, clean the whole files_dir (#1664)
files_dir_fig <- list.files(files_dir, '^figure-.+')

intermediates <- c(
intermediates,
if (length(files_dir_fig) < 1 || identical(files_dir_fig, basename(fig_path))) {
files_dir
} else {
fig_path
}
)
if (length(files_dir_fig) < 1 || identical(files_dir_fig, basename(fig_path))) {
files_dir
} else {
fig_path
}
}
intermediates <- c(intermediates, intermediates_fig)

file.copy(input, utf8_input, overwrite = TRUE)

Expand Down Expand Up @@ -968,6 +966,8 @@ render <- function(input,
attr(output_file, 'rmd_output_metadata') <- output_meta
invisible(output_file)
} else {
# make sure the markdown output and fig dir are not cleaned up
intermediates <- setdiff(intermediates, c(input, intermediates_fig))
# did not run pandoc; returns the markdown output with attributes of the
# knitr meta data and intermediate files
structure(input, knit_meta = knit_meta, intermediates = intermediates)
Expand Down

0 comments on commit c860cc2

Please sign in to comment.