Skip to content

Instantly share code, notes, and snippets.

@aL3xa
Created July 26, 2013 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aL3xa/6091138 to your computer and use it in GitHub Desktop.
Save aL3xa/6091138 to your computer and use it in GitHub Desktop.
Sweave script inspired by Dirk Eddelbuettel's answer on StackOverflow: http://stackoverflow.com/questions/2940756/ess-auctex-sweave-integration
#!/bin/bash
FILEBASE=${1%.*}
FILEXT=${1##*.}
FILEPATH=${1%/*}
TEXFILE=$FILEBASE.tex
PDFFILE=$FILEBASE.pdf
# errorexit
function errorexit () {
echo "Error: $1"
exit 1
}
# check if file exists
if [ ! -f $1 ]; then
errorexit "File $1 not found!"
else
# check for filename length
if [ ${#1} -lt 1 ]; then
errorexit "Need to specify argument file!"
else
# if filelength OK, check extension
if [ $FILEXT != "Rnw" ]; then
errorexit "You must pass Sweave (.Rnw) file!"
# finally, run Sweave
else
cd $FILEPATH && R CMD Sweave $1
# latex $TEXFILE
pdflatex $TEXFILE
xdg-open $PDFFILE &
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment