Debian Codegraph @

inst/bin/knit

raw symbols SCIP
1 #!/usr/bin/env Rscript
2
3 local({
4 p = commandArgs(TRUE)
5 if (length(p) == 0L || any(c('-h', '--help') %in% p)) {
6 message('usage: knit input [input2 input3] [-n] [-o output output2 output3]
7 -h, --help to print help messages
8 -n, --no-convert do not convert tex to pdf, markdown to html, etc
9 -o output filename(s) for knit()')
10 q('no')
11 }
12
13 library(knitr)
14 o = match('-o', p)
15 if (is.na(o)) output = NA else {
16 output = tail(p, length(p) - o)
17 p = head(p, o - 1L)
18 }
19 nc = c('-n', '--no-convert')
20 knit_fun = if (any(nc %in% p)) {
21 p = setdiff(p, nc)
22 knit
23 } else {
24 if (length(p) == 0L) stop('no input file provided')
25 if (grepl('\\.(R|S)(nw|tex)$', p[1])) {
26 function(x, ...) knit2pdf(x, ..., clean = TRUE)
27 } else {
28 if (grepl('\\.R(md|markdown)$', p[1])) knit2html else knit
29 }
30 }
31
32 mapply(knit_fun, p, output = output, MoreArgs = list(envir = globalenv()))
33 })