Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#' @rdname render_reports
#' @export
render_report <- function(path_report,
path_publish,
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 (!require("tinytex")) install.packages("tinytex")
}
if (clean_cache) {
cache_dir <- list.files(path = path,
pattern = "_cache$",
include.dirs = TRUE,
full.names = TRUE)
unlink(cache_dir, recursive = TRUE)
}
cfg_bookdown <-
yaml::read_yaml(file.path(path, "_bookdown.yml"))
unlink(file.path(path, paste0(cfg_bookdown$book_filename, ".*")))
output_dir <- file.path(path_publish, file)
dir.create(output_dir,
recursive = TRUE,
showWarnings = FALSE)
attached_packages <- (.packages())
bookdown::render_book(path,
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))
NULL
}