-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path_render.R
executable file
·37 lines (29 loc) · 1.13 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
quiet = "--quiet" %in% commandArgs(FALSE)
format = commandArgs(TRUE)
travis = !is.na(Sys.getenv('CI', NA))
# 配置源
local({
r = getOption('repos')
if (!length(r) || all(r['CRAN'] == '@CRAN@')) r['CRAN'] = 'https://cran.rstudio.com'
options(repos = r)
})
# 填上你需要用到的包
if (system.file(package = 'rmarkdown') == '')
remotes::install_github('rstudio/rmarkdown')
if (system.file(package = 'bookdown') == '')
install.packages('bookdown')
lapply(c('diagram','DT', 'citr', 'formatR', 'svglite', 'webshot', 'devtools', 'shape'), function(pkg) {
if (system.file(package = pkg) == '') install.packages(pkg)
})
src = (function() {
attr(body(sys.function()), 'srcfile')
})()$filename
if (is.null(src) || src == '') src = '.'
owd = setwd(dirname(src))
# provide default format if necessary
if (length(format) == 0) format = 'bookdown::pdf_book'
# render the book to all formats unless they are specified via command-line args
cmd = sprintf("bookdown::render_book('index.Rmd', '%s', quiet = %s)", format, quiet)
res = bookdown:::Rscript(c('-e', shQuote(cmd)))
if (res != 0) stop('Failed to compile the book to ', format)
setwd(owd)