[R] cygwin script for Sweave

Thomas Harte
Fri, 13 Oct 2006 16:20:01 -0000

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 &
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<