-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy path_render.R
26 lines (22 loc) · 861 Bytes
/
_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
quiet = "--quiet" %in% commandArgs(FALSE)
formats = commandArgs(TRUE)
travis = !is.na(Sys.getenv('CI', NA))
src = (function() {
attr(body(sys.function()), 'srcfile')
})()$filename
if (is.null(src) || src == '') src = '.'
owd = setwd(dirname(src))
# provide default formats if necessary
if (length(formats) == 0) formats = c(
'bookdown::pdf_book', 'bookdown::epub_book', 'bookdown::gitbook'
)
# render the book to all formats unless they are specified via command-line args
for (fmt in formats) {
cmd = sprintf("bookdown::render_book('index.Rmd', '%s', quiet = %s)", fmt, quiet)
res = bookdown:::Rscript(c('-e', shQuote(cmd)))
if (res != 0) stop('Failed to compile the book to ', fmt)
if (!travis && fmt == 'bookdown::epub_book')
bookdown::calibre('_book/bookdown.epub', 'mobi')
}
if (length(formats) > 1) bookdown::publish_book()
setwd(owd)