]> git.lyx.org Git - features.git/commitdiff
Handle encoding correctly with knitr>=1.0 (#8504)
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 21 Jan 2013 08:48:28 +0000 (09:48 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 21 Jan 2013 14:57:18 +0000 (15:57 +0100)
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
status.20x

index 7c029ead06adf29de3f7dc406d38db139472ab75..438b40a3e7df7fdde0773d11d75c164213e55019 100644 (file)
 ## $$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)
+}
index 6ad00b89c37b3b70217b5b56fc55c628b5be5116..545505110ee3b6a183fd83a618501e8d3f9f136f 100644 (file)
@@ -82,6 +82,9 @@ What's new
 - Fix problem using lyxpak.py when outside the LyX tree: Variable was
   undefined.
 
+- When using the knitr module, use new "encoding" parameter of knitr if 
+  available (bug 8504).
+
 - Respect InsetLayout's PassThru setting for XHTML export.
 
 - Fix layout conversion bug involving quoted Flex inset names that do not