Skip to content

Instantly share code, notes, and snippets.

@nelsonauner
Forked from kleinschmidt/knit.sh
Created June 18, 2014 09:29
Show Gist options
  • Save nelsonauner/af155b771ae45105ef73 to your computer and use it in GitHub Desktop.
Save nelsonauner/af155b771ae45105ef73 to your computer and use it in GitHub Desktop.
#!/bin/bash
# knit.sh -- Dave Kleinschmidt, April 2013
# streamline knitting of Rnw files from the command line.
usage="Usage: $0 input-filename.Rnw [-nolatex] [-notangle]"
if [ $# -lt 1 ]; then
echo $usage
exit 1
fi
rnwinput=$1
shift
nolatex=0
notangle=0
while [ $# -gt 0 ]
do
case "$1" in
-nolatex) nolatex=1;;
-notangle) notangle=1;;
-*) echo $usage >&2
exit 1;;
*) break;;
esac
shift
done
# first knit Rnw file into
fileName=${rnwinput%.*}
echo "library(knitr); knit(input='$rnwinput');" | R --no-save --no-restore
if [ $notangle -ne 1 ]; then
echo "library(knitr); knit(input='$rnwinput', tangle=T);" | R --no-save --no-restore
fi
if [ $nolatex -ne 1 ]; then
pdflatex ${fileName}.tex && pdflatex ${fileName}.tex
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment