Last active
August 13, 2021 18:05
-
-
Save metamaden/14f6b5717e2934c118ffa9edfa45e765 to your computer and use it in GitHub Desktop.
Shell script to run the 3 main R package check types.
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
#!/usr/bin/env sh | |
# Author: Sean Maden | |
# | |
# Script to install, build, and check R packages during development. Can perform | |
# one of 3 check types (R CHECK with and without '--as-cran', or BiocCheck). | |
# | |
# Flags: | |
# -v : Build vignettes (otherwise use `... --no-build-vignettes`) | |
# -r : Run `R CMD CHECK ...` | |
# -b : Run `R BiocCheck ...` | |
# -c : Run CRAN check (e.g. `R CMD CHECK --as-cran ...`) | |
# | |
# Returns: | |
# Builds the package, generates tarball containing the built binaries and check | |
# logs. | |
#------------ | |
# parse flags | |
#------------ | |
# initialize flag variables | |
packagepath= | |
buildvignettes=0 | |
rcheck=0 | |
bioccheck=0 | |
crancheck=0 | |
# parse provided flags | |
while getopts vrbchp: name; do | |
case "$name" in | |
'v') buildvignettes=1;; | |
'r') rcheck=1;; | |
'b') bioccheck=1;; | |
'c') crancheck=1;; | |
'p') packagepath=$OPTARG;; | |
\?) echo "Invalid option provided: -$OPTARG" >&2;; | |
esac | |
done | |
#------------------------- | |
# package setup for checks | |
#------------------------- | |
# check package path existence | |
if [ ! -d "$packagepath" ]; then | |
echo 'ERROR: invalid package path provided' | |
exit 1 | |
fi | |
# prep the package | |
R CMD INSTALL $packagepath | |
# parse buildvignettes flag | |
if [ $buildvignettes == 0 ]; then | |
echo 'Skipping vignette builds...' | |
R CMD BUILD $packagepath --no-build-vignettes | |
else | |
echo 'Building vignettes...' | |
R CMD BUILD $packagepath | |
fi | |
# prep the tar path | |
packagename=$(basename $packagepath) | |
# get the version from description text | |
vers=$(sed '2q;d' $packagepath'/DESCRIPTION') | |
vf=${vers:9} | |
tarpath=$packagename'_'$vf'.tar.gz' # detect the tar file | |
#--------------------- | |
# run specified checks | |
#--------------------- | |
if [ ! $rcheck == 0 ]; then | |
echo 'Running `R CMD CHECK`...' | |
R CMD CHECK $tarpath | |
fi | |
if [ ! $bioccheck == 0 ]; then | |
echo 'Running `R CMD BiocCheck`...' | |
R CMD BiocCheck $tarpath | |
fi | |
if [ ! $crancheck == 0 ]; then | |
echo 'Running `R CMD CHECK --as-cran`...' | |
R CMD CHECK --as-cran $tarpath | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment