[R] cygwin script for Sweave

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Oct 14 09:07:22 CEST 2006


Your version of R is old: see R CMD Sweave in the current versions.

On Fri, 13 Oct 2006, Thomas Harte wrote:

> 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 &
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list