X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fscripts%2Flyxknitr.R;h=438b40a3e7df7fdde0773d11d75c164213e55019;hb=fa38ae3fc0f6e957f9b7115d04e72c121b39cf92;hp=7c029ead06adf29de3f7dc406d38db139472ab75;hpb=f7928f48a6e5d92bd068c19f6b3d6f09d2c7012a;p=lyx.git diff --git a/lib/scripts/lyxknitr.R b/lib/scripts/lyxknitr.R index 7c029ead06..438b40a3e7 100644 --- a/lib/scripts/lyxknitr.R +++ b/lib/scripts/lyxknitr.R @@ -21,12 +21,8 @@ ## $$e encoding (e.g. 'UTF-8') library(knitr) - .cmdargs = commandArgs(TRUE) -.orig.enc = getOption("encoding") -options(encoding = .cmdargs[3]) - ## the working directory is the same with the original .lyx file; you ## can put your data files there and functions like read.table() can ## work correctly without specifying the full path @@ -34,4 +30,11 @@ setwd(.cmdargs[4]) opts_knit$set(root.dir = getwd()) ## run knit() to get .tex or .R -knit(.cmdargs[1], output = .cmdargs[2], tangle = 'tangle' %in% .cmdargs) +if (is.null(formals(knit)$encoding)) { + .orig.enc = getOption("encoding") + options(encoding = .cmdargs[3]) + knit(.cmdargs[1], output = .cmdargs[2], tangle = 'tangle' %in% .cmdargs) +} else { + knit(.cmdargs[1], output = .cmdargs[2], encoding = .cmdargs[3], + tangle = 'tangle' %in% .cmdargs) +}