#' @rdname render_reports #' @inheritParams bookdown::render_book #' @export render_report <- function(input, output_dir, output_format = Sys.getenv("BOOKDOWN_FORMAT", "bookdown::gitbook"), clean_cache = FALSE, ...) { stopifnot(output_format %in% c("bookdown::gitbook", "bookdown::pdf_book")) if (output_format == "bookdown::pdf_book") { if (!requireNamespace("tinytex", quietly=TRUE)) install.packages("tinytex") } message("output_format=", output_format) if (clean_cache) { cache_dir <- list.files(path = input, pattern = "_cache$", include.dirs = TRUE, full.names = TRUE) unlink(cache_dir, recursive = TRUE) } cfg_bookdown <- yaml::read_yaml(file.path(input, "_bookdown.yml")) unlink(file.path(input, paste0(cfg_bookdown$book_filename, ".*"))) attached_packages <- (.packages()) bookdown::render_book(input, output_format = output_format, output_dir = output_dir, envir = new.env(), ...) # detach all packages used in the knit sapply( setdiff((.packages()), attached_packages), function(x) detach(paste0("package:", x), unload = TRUE, character.only = TRUE)) invisible() }