@@ -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