#!/bin/sh -e

biocname=snpStats
pkg=r-bioc-`echo $biocname | tr '[A-Z]' '[a-z]'`

if [ "$ADTTMP" = "" ] ; then
  ADTTMP=`mktemp -d /tmp/${pkg}-test.XXXXXX`
fi
cd $ADTTMP
cp /usr/share/doc/$pkg/examples/vignettes/* $ADTTMP
find . -name "*.gz" -exec gunzip \{\} \;
export LC_ALL=C
for rnw in *.Rnw ; do
    echo "====================== $rnw ============================"
    rfile=`basename $rnw nw`
    if [ "$rnw" = "imputation-vignette.Rnw" ] ; then # -o "$rnw" = "ld-vignette.Rnw" ]
        echo "Test "$rnw" needs r-cran-hexbin which is not yet packaged."
    else
        if [ "$rnw" = "snpStats-vignette.Rnw" ] ; then
            echo "Test $rnw needs allest[""rs10882596""] but it is not clear where to get this."
        else
            R --no-save <<EOT
                Stangle("$rnw")
                source("$rfile", echo=TRUE)
EOT
        fi
    fi
done

