Skip to content

Commit c860cc2

Browse files
committed
fix #1812: when render(run_pandoc = FALSE), exclude the .md output file and associated figure files from the list of intermediate files, so they won't be cleaned up
1 parent 7bc6575 commit c860cc2

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: rmarkdown
22
Type: Package
33
Title: Dynamic Documents for R
4-
Version: 2.1.9
4+
Version: 2.1.10
55
Authors@R: c(
66
person("JJ", "Allaire", role = "aut", email = "[email protected]"),
77
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ rmarkdown 2.2
2727

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

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

3133
rmarkdown 2.1
3234
================================================================================

R/render.R

+9-9
Original file line numberDiff line numberDiff line change
@@ -780,23 +780,21 @@ render <- function(input,
780780
# the knitr cache is active; clean the figure-* dir instead of the whole
781781
# files_dir if other subdirs are generated by another format and still needed:
782782
# https://github.com/rstudio/rmarkdown/issues/1472 and also #1503
783-
if (output_format$clean_supporting && !dir_exists(cache_dir)) {
783+
intermediates_fig <- if (output_format$clean_supporting && !dir_exists(cache_dir)) {
784784
# unlink does not support / at the end of file path
785785
fig_path <- gsub("/$", "", knitr::opts_chunk$get('fig.path'))
786786

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

791-
intermediates <- c(
792-
intermediates,
793-
if (length(files_dir_fig) < 1 || identical(files_dir_fig, basename(fig_path))) {
794-
files_dir
795-
} else {
796-
fig_path
797-
}
798-
)
791+
if (length(files_dir_fig) < 1 || identical(files_dir_fig, basename(fig_path))) {
792+
files_dir
793+
} else {
794+
fig_path
795+
}
799796
}
797+
intermediates <- c(intermediates, intermediates_fig)
800798

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

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

0 commit comments

Comments
 (0)