From 95164fa0a362ab7eda43eb98661996057b2e6157 Mon Sep 17 00:00:00 2001 From: Taha Ahmed Date: Wed, 3 Oct 2012 20:23:04 +0200 Subject: [PATCH] Added support for knitr jobs as well. chertex.sh will use knitr instead of pgfSweave if it detects a file name ".knitme" in the directory of the current job. Crude solution, but it should work. --- chertex.sh | 60 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/chertex.sh b/chertex.sh index 917787d..f081ab1 100755 --- a/chertex.sh +++ b/chertex.sh @@ -59,20 +59,49 @@ if [ $# -eq 1 ]; then # Introducing a short delay to enable on-screen reading of previous echo simpledelay.sh 2 echo "Delay completed" - - # Tangle - echo " Tangling..." - R CMD Stangle $jobname.$jobfiletype - # Weave - echo " Weaving..." - R CMD pgfsweave --graphics-only $jobname.$jobfiletype - - # Introduce delay to give time to read R CMD exit status - echo " -------------------------" - echo " R CMD pgfsweave completed" - echo " -------------------------" - simpledelay.sh 4 + + ## Handle knitr or pgfSweave jobs separately + ## But how should we tell the difference between them? + ## There is no obvious way to tell the difference (apart from reading the *.Rnw file) + ## IN ALL KNITR DIRECTORIES, CREATE A FILE NAMED: .knitme + # If the file .knitme exists in the current directory, + # run knitr commands, otherwise run pgfsweave commands + echo "--- Looking for .knitme" + if [ -e .knitme ]; then + # Run knitr commands for this job + echo " -----------------------" + echo " This is a job for knitr" + echo " -----------------------" + + # Knit + echo " Knitting..." + Rscript -e "library(knitr); library(methods); knit('$jobname.$jobfiletype')" + + # Introduce delay to give time to read Rscript exit status + echo " -----------------------" + echo " Rscript knitr completed" + echo " -----------------------" + simpledelay.sh 4 + else + # Run pgfSweave commands + echo " ---------------------------" + echo " This is a job for pgfSweave" + echo " ---------------------------" + + # Tangle + echo " Tangling..." + R CMD Stangle $jobname.$jobfiletype + # Weave + echo " Weaving..." + R CMD pgfsweave --graphics-only $jobname.$jobfiletype + # Introduce delay to give time to read R CMD exit status + echo " -------------------------" + echo " R CMD pgfsweave completed" + echo " -------------------------" + simpledelay.sh 4 + fi + # Run vc script if vc exists in working directory echo " Running vc script" if [ -f vc ]; then @@ -204,6 +233,11 @@ else if [ $cssfiles != 0 ]; then cp /home/taha/chepec/tmp/$tmpdirname/*.css . fi + # Return .knitme file [empty file used to indicate knitr jobs] + knitmefile=`ls -1 /home/taha/chepec/tmp/$tmpdirname/.knitme 2>/dev/null | wc -l` + if [ $knitmefile != 0 ]; then + cp /home/taha/chepec/tmp/$tmpdirname/.knitme . + fi fi echo "Terminating..."