@@ -780,23 +780,21 @@ render <- function(input,
780
780
# the knitr cache is active; clean the figure-* dir instead of the whole
781
781
# files_dir if other subdirs are generated by another format and still needed:
782
782
# 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 )) {
784
784
# unlink does not support / at the end of file path
785
785
fig_path <- gsub(" /$" , " " , knitr :: opts_chunk $ get(' fig.path' ))
786
786
787
787
# existing figure folder(s), can be character(0)
788
788
# if no figure is generated, clean the whole files_dir (#1664)
789
789
files_dir_fig <- list.files(files_dir , ' ^figure-.+' )
790
790
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
+ }
799
796
}
797
+ intermediates <- c(intermediates , intermediates_fig )
800
798
801
799
file.copy(input , utf8_input , overwrite = TRUE )
802
800
@@ -968,6 +966,8 @@ render <- function(input,
968
966
attr(output_file , ' rmd_output_metadata' ) <- output_meta
969
967
invisible (output_file )
970
968
} else {
969
+ # make sure the markdown output and fig dir are not cleaned up
970
+ intermediates <- setdiff(intermediates , c(input , intermediates_fig ))
971
971
# did not run pandoc; returns the markdown output with attributes of the
972
972
# knitr meta data and intermediate files
973
973
structure(input , knit_meta = knit_meta , intermediates = intermediates )
0 commit comments