Created
July 26, 2013 18:29
-
-
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
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