Created
September 13, 2011 10:27
-
-
Save aL3xa/1213552 to your computer and use it in GitHub Desktop.
Custom Sweave bash script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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