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.
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.
13 ## knitr is an alternative package to Sweave, and has more features
14 ## and flexibility; see https://yihui.name/knitr
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
20 ## $$r path to the original input file (the lyx document)
21 ## $$e encoding (e.g. 'UTF-8')
24 .cmdargs = commandArgs(TRUE)
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
30 opts_knit$set(root.dir = getwd())
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)
38 knit(.cmdargs[1], output = .cmdargs[2], encoding = .cmdargs[3],
39 tangle = 'tangle' %in% .cmdargs)