]> git.lyx.org Git - features.git/commitdiff
Add possibility to export the R code from a sweave-enabled document
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 23 Aug 2011 10:33:42 +0000 (10:33 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 23 Aug 2011 10:33:42 +0000 (10:33 +0000)
(patch from yihui, part of #7555)
http://www.lyx.org/trac/ticket/7555#comment:18

This adds the new format "R/S code" with extension .R and a converter from .Rnw.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39509 a592a061-630c-0410-9148-cb99ea01b6c8

development/scons/scons_manifest.py
lib/Makefile.am
lib/configure.py
lib/scripts/lyxstangle.R [new file with mode: 0644]

index 15d83e433fff3c61ad8020b42f4745a17a9873f7..cfe3e32bd2a2932e3e873d3ffa6e05d0bb094284 100644 (file)
@@ -3015,6 +3015,7 @@ lib_scripts_files = Split('''
     lyxpreview-lytex2bitmap.py
     lyxpreview-platex2bitmap.py
     lyxpreview_tools.py
+    lyxstangle.R
     lyxsweave.R
     prefs2prefs.py
     prefs2prefs_lfuns.py
index ef2066b27a55b985033e390863847c1499b2697c..4aad3d3f01869ea7025abad89b40719ab0fc24e6 100644 (file)
@@ -1484,6 +1484,7 @@ dist_layouts_DATA =\
 scriptsdir = $(pkgdatadir)/scripts
 dist_scripts_DATA = \
        scripts/bash_completion \
+       scripts/lyxstangle.R \
        scripts/lyxsweave.R
 # Note that we "chmod 755" manually these files in install-data-hook.
 dist_scripts_PYTHON = \
index 872e2ac50d2d064837ea07c4459770bcc6f310f0..f6b620c03d6f5f78fa71f7c73e7700d52efa1d96 100644 (file)
@@ -513,6 +513,7 @@ def checkFormatEntries(dtl_tools):
 \Format platex     tex    "LaTeX (pLaTeX)"        "" "" "%%"    "document,menu=export"
 \Format literate   nw      NoWeb                  N  ""        "%%"    "document,menu=export"
 \Format sweave     Rnw    "Sweave"                S  "" "%%"    "document,menu=export"
+\Format r          R      "R/S code"              "" "" "%%"    "document,menu=export"
 \Format lilypond   ly     "LilyPond music"        "" ""        "%%"    "vector"
 \Format lilypond-book    lytex "LilyPond book (LaTeX)"   "" "" "%%"    "document,menu=export"
 \Format latex      tex    "LaTeX (plain)"         L  ""        "%%"    "document,menu=export"
@@ -612,21 +613,13 @@ def checkConverterEntries():
 
     checkLuatex()
 
-    ''' If we're running LyX in-place then tex2lyx will be found in
-            ../src/tex2lyx. Add this directory to the PATH temporarily and
-            search for tex2lyx.
-            Use PATH to avoid any problems with paths-with-spaces.
-    '''
-    path_orig = os.environ["PATH"]
-    os.environ["PATH"] = os.path.join('..', 'src', 'tex2lyx') + \
-        os.pathsep + path_orig
-
-# First search for tex2lyx with version suffix (bug 6986)
+# First search for tex2lyx with version suffix (bug 6986). If nothing
+# has been found, use 'tex2lyx' which is present in the build tree
+# when running in place.
     checkProg('a LaTeX/Noweb -> LyX converter', ['tex2lyx' + version_suffix, 'tex2lyx'],
         rc_entry = [r'''\converter latex      lyx        "%% -f $$i $$o"       ""
-\converter literate   lyx        "%% -n -f $$i $$o"    ""'''])
-
-    os.environ["PATH"] = path_orig
+\converter literate   lyx        "%% -n -f $$i $$o"    ""'''], 
+        not_found = 'tex2lyx')
 
     #
     checkProg('a Noweb -> LaTeX converter', ['noweave -delay -index $$i > $$o'],
@@ -639,6 +632,9 @@ def checkConverterEntries():
 \converter sweave   xetex      "%%"    ""
 \converter sweave   luatex     "%%"    ""'''])
     #
+    checkProg('a Sweave -> R/S code converter', ['Rscript --verbose --no-save --no-restore $$s/scripts/lyxstangle.R $$i $$e $$r'], 
+        rc_entry = [ r'\converter sweave      r      "%%"    ""' ])
+    #
     checkProg('an HTML -> LaTeX converter', ['html2latex $$i', 'gnuhtml2latex $$i', \
         'htmltolatex -input $$i -output $$o', 'java -jar htmltolatex.jar -input $$i -output $$o'],
         rc_entry = [ r'\converter html       latex      "%%"   ""' ])
diff --git a/lib/scripts/lyxstangle.R b/lib/scripts/lyxstangle.R
new file mode 100644 (file)
index 0000000..93fb611
--- /dev/null
@@ -0,0 +1,16 @@
+## file lyxstangle.R
+## This file is part of LyX, the document processor.
+## Licence details can be found in the file COPYING.
+
+## author Yihui Xie
+
+## Full author contact details are available in file CREDITS
+
+## Rscript $$s/scripts/lyxstangle.R $$i $$e $$r
+
+.cmdargs = commandArgs(TRUE)
+
+options(encoding = .cmdargs[2])
+
+## run Stangle to extract R code
+Stangle(.cmdargs[1])