[R] cygwin script for Sweave

Thomas Harte thomas.harte at yahoo.com
Fri Oct 13 18:20:01 CEST 2006


below is a very simple bash script to run Sweave from a cygwin terminal, run pdflatex on 
the generated .tex file, and then view the resulting .pdf output.

i usually use cygwin when i am (forced to be on) Windoze, but i found a few issues 
with paths that this script works around.

pdfview, used in the script, is simply:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$ cat /usr/local/bin/pdfview
#!/bin/bash.exe

if [ $# -eq 1 ]
then
        /c/Program\ Files/Adobe/Acrobat\ 6.0/Reader/AcroRd32.exe `cygpath -w -a -s "$1"`
else
        /c/Program\ Files/Adobe/Acrobat\ 6.0/Reader/AcroRd32.exe
fi
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

mutatis mutandis for your own Adobe Reader. 


here is the script:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/bin/bash.exe
# rnw.sh [.Rnw file]
#
# $1 must be a .Rnw file
#
RNWFILE=$1
PWD=`pwd`
FILEBASE=`basename $1 .Rnw`
TEXFILE=$FILEBASE.tex
PDFFILE=$FILEBASE.pdf

echo " \
	library(\"utils\"); 		\
	setwd(\"`cygpath -m $PWD`\"); 	\
	Sweave(\"$RNWFILE\")		\
      " 				\
      | /c/R/R-2.3.1/bin/Rterm.exe --no-save --no-restore
     
# the resulting .tex file contains an annoying "c:" ... 
# replace it with the pdflatex-friendly "/c" :
sed -e 's/c:/\/c/g' --in-place $TEXFILE

# now run text processing
pdflatex $TEXFILE
pdfview $PDFFILE &
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



More information about the R-help mailing list