Skip to content

Instantly share code, notes, and snippets.

@aL3xa
Created September 13, 2011 10:27
Show Gist options
  • Save aL3xa/1213552 to your computer and use it in GitHub Desktop.
Save aL3xa/1213552 to your computer and use it in GitHub Desktop.
Custom Sweave bash script
#!/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