Author: lasgouttes
Date: Thu Feb  2 23:30:38 2012
New Revision: 40703
URL: http://www.lyx.org/trac/changeset/40703

Log:
Fix #8019 (from yihui)
* avoid creation of file Rplots.pdf in document file
* find correctly Sweave.sty on old R versions

Modified:
   lyx-devel/trunk/lib/scripts/lyxsweave.R

Modified: lyx-devel/trunk/lib/scripts/lyxsweave.R
==============================================================================
--- lyx-devel/trunk/lib/scripts/lyxsweave.R     Thu Feb  2 16:59:45 2012        
(r40702)
+++ lyx-devel/trunk/lib/scripts/lyxsweave.R     Thu Feb  2 23:30:38 2012        
(r40703)
@@ -23,8 +23,12 @@
 # The advantage compared to the use of stylepath, is that the exported
 # .tex file will be portable to another machine. (JMarc)
 if (!length(system("kpsewhich Sweave.sty", intern=TRUE, ignore.stderr=TRUE))) {
-  file.copy(file.path(R.home("share"), "texmf", "tex", "latex", "Sweave.sty"),
-    dirname(.cmdargs[2]), overwrite=TRUE)
+  .texmf.path <- file.path(R.home("share"), "texmf")
+  if (!file.exists(.sweave.sty <- file.path(.texmf.path, "Sweave.sty"))) {
+    .sweave.sty <- file.path(.texmf.path, "tex", "latex", "Sweave.sty")
+  } 
+  file.copy(.sweave.sty, dirname(.cmdargs[2]), overwrite=TRUE)
+  rm(list = c('.sweave.sty', '.texmf.path'))
 }
 
 
@@ -39,6 +43,11 @@
 .prefix.str <- paste(dirname(.cmdargs[2]), tmpout, sep="/")
 rm(tmpout)
 
+# avoid the default Rplots.pdf
+options(device = function(...) {
+  pdf(file = tempfile())
+})
+
 # finally run sweave
 
 # The Sweave version provided with R >= 0.13.1 has proper handling for

Reply via email to