]> git.lyx.org Git - lyx.git/blob - lib/scripts/lyxknitr.R
ext_copy: bug when creating the error string.
[lyx.git] / lib / scripts / lyxknitr.R
1 ## This program is free software; you can redistribute it and/or
2 ## modify it under the terms of the GNU General Public License as
3 ## published by the Free Software Foundation; either version 2 of the
4 ## License, or (at your option) any later version.
5 ##
6 ## This program is distributed in the hope that it will be useful, but
7 ## WITHOUT ANY WARRANTY; without even the implied warranty of
8 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 ## General Public License for more details.
10
11 ## author Yihui Xie
12
13 ## knitr is an alternative package to Sweave, and has more features
14 ## and flexibility; see https://yihui.name/knitr
15
16 ## Rscript $$s/scripts/lyxknitr.R $$p$$i $$p$$o $$e $$r
17 ## $$p the path of the output (temp dir)
18 ## $$i the file name of the input Rnw
19 ## $$o the tex output
20 ## $$r path to the original input file (the lyx document)
21 ## $$e encoding (e.g. 'UTF-8')
22
23 library(knitr)
24 .cmdargs = commandArgs(TRUE)
25
26 ## the working directory is the same with the original .lyx file; you
27 ## can put your data files there and functions like read.table() can
28 ## work correctly without specifying the full path
29 setwd(.cmdargs[4])
30 opts_knit$set(root.dir = getwd())
31
32 ## run knit() to get .tex or .R
33 if (is.null(formals(knit)$encoding)) {
34   .orig.enc = getOption("encoding")
35   options(encoding = .cmdargs[3])
36   knit(.cmdargs[1], output = .cmdargs[2], tangle = 'tangle' %in% .cmdargs)
37 } else {
38   knit(.cmdargs[1], output = .cmdargs[2], encoding = .cmdargs[3],
39        tangle = 'tangle' %in% .cmdargs)
40 }