-
Notifications
You must be signed in to change notification settings - Fork 7
/
_render.R
45 lines (39 loc) · 1.34 KB
/
_render.R
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
43
44
45
options(warn = 1)
library(cliapp)
start_app(theme = simple_theme())
cli_h1("Preprocessing")
# spelling check
cli_h2("Spelling check")
rmd_files <- list.files("Rmd", pattern = "*.Rmd", full.names = TRUE, recursive = TRUE)
wordlist <- readLines("WORDLIST")
spell_res <- spelling::spell_check_files(rmd_files, wordlist, "en_US")
if (length(spell_res$word) > 0) {
print(spell_res)
stop("Can you please fix typos listed above first?", call. = FALSE)
}
# convert pdf to png for html output
cli_h2("Coverting pdf to png")
img_pdf <- list.files("img/", pattern = "*.pdf")
for (i in img_pdf) {
file_pdf <- paste0("img/", i)
dest_pdf <- paste0("img/", sub("pdf$", "png", i))
magick::image_write(
magick::image_read(file_pdf, 300), dest_pdf, "png",
density = 300
)
}
cli_h1("Compiling")
if (Sys.getenv("RSTUDIO") != "1" && Sys.info()['sysname'] == "Darwin") {
Sys.setenv('RSTUDIO_PANDOC' = '/Applications/RStudio.app/Contents/MacOS/pandoc')
}
# provide default formats if necessary
formats <- commandArgs(trailingOnly = TRUE)
if (length(formats) == 0) {
formats <- "bookdown::pdfbook"
}
# render the book to all formats
for (fmt in formats)
bookdown::render_book("index.Rmd", fmt, quiet = FALSE)
gif_file <- list.files("figure", "*.gif", full.names = TRUE)
invisible(file.copy(gif_file, "_thesis/figure/animate.gif"))
cli_alert_success("You Rock!")