-
-
Notifications
You must be signed in to change notification settings - Fork 873
/
knit-all.R
executable file
·41 lines (34 loc) · 1.06 KB
/
knit-all.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
#!/usr/bin/env Rscript
if (!nzchar(Sys.which('lyx')) || system('lyx -version') != 0L) q()
call_lyx = function(file) {
res = sapply(sprintf('lyx -e %s %s', c('knitr', 'r', 'pdf2'), file),
system, USE.NAMES = FALSE)
unlink(sub('\\.lyx$', '.R', file))
stopifnot(identical(res, integer(3L)))
}
for (i in list.files(pattern = '\\.lyx$')) {
message(i)
call_lyx(i)
flush.console()
}
call_knit = function(cmd) {
stopifnot(identical(system(cmd), 0L))
}
for (i in list.files(pattern = '\\.Rmd')) {
message(i)
cmd = if (i == 'knitr-minimal.Rmd') {
sprintf("Rscript -e 'library(knitr);opts_knit$set(base.url=\"https://github.com/yihui/knitr/raw/master/inst/examples/\");opts_chunk$set(fig.path=\"\");knit(\"%s\")'", i)
} else {
sprintf('knit %s', i)
}
call_knit(cmd)
flush.console()
}
call_knit(sprintf("Rscript -e 'library(knitr);spin(\"knitr-spin.R\")'"))
setwd('child')
for (i in c('knitr-main.Rnw', 'knitr-parent.Rnw')) {
call_knit(sprintf('knit %s --pdf', i))
}
unlink('*.tex')
call_knit(sprintf('knit %s', 'knitr-main.Rmd'))
setwd('..')