Remove all the files and folders created when rendering a qmd to html
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)