Debian Codegraph @

inst/examples/knit-all.R

raw
1 #!/usr/bin/env Rscript
2
3 if (!nzchar(Sys.which('lyx')) || system('lyx -version') != 0L) q()
4
5 call_lyx = function(file) {
6 res = sapply(sprintf('lyx -e %s %s', c('knitr', 'r', 'pdf2'), file),
7 system, ignore.stdout = TRUE, USE.NAMES = FALSE)
8 unlink(sub('\\.lyx$', '.R', file))
9 stopifnot(identical(res, integer(3L)))
10 }
11
12 for (i in list.files(pattern = '\\.lyx$')) {
13 message(i)
14 call_lyx(i)
15 flush.console()
16 }
17
18 knit_script = normalizePath('../bin/knit', mustWork = TRUE)
19 knit_cmd = function(file) {
20 paste('Rscript', shQuote(knit_script), shQuote(file))
21 }
22 test_cmd = function(cmd) {
23 stopifnot(identical(system(cmd, ignore.stdout = TRUE), 0L))
24 }
25
26 for (i in list.files(pattern = '\\.Rmd')) {
27 message(i)
28 cmd = if (i == 'knitr-minimal.Rmd') {
29 sprintf("Rscript -e 'library(knitr);opts_knit$set(base.url=\"http://animation.r-forge.r-project.org/ideas/\");knit(\"%s\")'", i)
30 } else knit_cmd(i)
31 test_cmd(cmd)
32 flush.console()
33 }
34
35 test_cmd(sprintf("Rscript -e 'library(knitr);spin(\"knitr-spin.R\", precious=TRUE)'"))
36
37 setwd('child')
38 for (i in c('knitr-main.Rnw', 'knitr-parent.Rnw')) {
39 test_cmd(knit_cmd(i))
40 }
41 unlink('*.tex')
42 test_cmd(knit_cmd('knitr-main.Rmd'))
43 setwd('..')
44
45 file.remove('child/knitr-main.html')