From c48bdf845c8d650a67dfb14da54fe2bd5fc2cd1f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 21 Jan 2013 09:48:28 +0100 Subject: [PATCH] Handle encoding correctly with knitr>=1.0 (#8504) Knitr now has a parameter to indicate the encoding of the file. With this patch,it is used when possible (from Yihui Xie). --- lib/scripts/lyxknitr.R | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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) +} -- 2.39.2