Skip to contents

Remove all the files and folders created when rendering a qmd to html

Usage

clean_rendering_files(dir, present_before, extra_dir = NULL)

Arguments

dir

character. The directory to look for rendering output recursively.

present_before

character. Path to the files and directories present before rendering.

extra_dir

character. Path of additional directories to remove.

Value

None. Side effect: remove files that were not present before rendering

Examples

# create a temp dir with qmd
temp_dir <- tempfile(pattern = "clean")

dir.create(
  path = file.path(temp_dir, "img"),
  recursive = TRUE
)

file.copy(
  from = system.file("courses", "M01", "M01S01", "C01-qmd1_for_test.qmd", package = "squash"),
  to = temp_dir
)
#> [1] TRUE

file.copy(
  from = system.file("courses", "M01", "M01S01", "img", "logo_1.png", package = "squash"),
  to = file.path(temp_dir, "img")
)
#> [1] TRUE

# list files before rendering
file_and_dirs_before <- list.files(
  temp_dir,
  recursive = TRUE,
  full.names = TRUE,
  include.dirs = TRUE
)

# render qmd
quarto::quarto_render(
  input = file.path(temp_dir, "C01-qmd1_for_test.qmd"),
  quiet = TRUE
)

# remove created files and dirs
clean_rendering_files(
  dir = temp_dir,
  present_before = file_and_dirs_before
)

# clean temp dir
unlink(temp_dir, recursive = TRUE)