Last active
December 12, 2016 16:30
-
-
Save mpadge/75a0ef612d095234f8ac3a8f8da07740 to your computer and use it in GitHub Desktop.
R package skeleton
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 | |
# AUTHORS: Bob Rudis <[email protected]> (@hrbrmstr) | |
# Mark Padgham <[email protected]> | |
# LICENSE: MIT + file zLICENSE | |
# | |
# Adapted by Mark Padgham from original gist of Bob Rudis | |
TODAY=`date +%Y-%m-%d` | |
TODAY_MD=`date +%B\ %d,\ %Y` | |
YEAR=`date +%Y` | |
PACKAGENAME=$1 | |
############################ | |
## | |
### CHANGE ME!!! | |
## | |
# | |
# where your dev base is | |
DEV_HOME=/data/Dropbox/mark/code/repos | |
# | |
# author name | |
AUTNAME="Mark Padgham" | |
# travis/github/etc handle | |
HANDLE=mpadge | |
# | |
############################ | |
# start pkg setup | |
PKGDIR=$DEV_HOME'/'$PACKAGENAME | |
if [ ! -d "$PKGDIR" ]; then | |
mkdir $PKGDIR | |
fi | |
Rscript --no-save -e "devtools::create('$PKGDIR', rstudio=FALSE)" | |
cd $PKGDIR | |
cat <<EOF >LICENSE | |
YEAR: $YEAR | |
COPYRIGHT HOLDER: $AUTNAME | |
EOF | |
# setup git | |
#Rscript --no-save -e "devtools::use_git()" | |
git init | |
echo "------------------------------------" | |
read -p "Clone from existing git repo? " OPT | |
echo "------------------------------------" | |
if [ "$OPT" == "y" ] || [ "$OPT" == "Y" ] | |
then | |
REPO="https://github.com/"$HANDLE"/"$PACKAGENAME".git" | |
git remote add origin $REPO | |
git fetch | |
git checkout -t origin/master # -t sets upstream branch | |
fi | |
# add README.Rmd | |
Rscript --no-save -e "devtools::use_readme_rmd('$PKGDIR')" | |
# sets up test harness | |
Rscript --no-save -e "devtools::use_testthat()" | |
# CI | |
Rscript --no-save -e "devtools::use_travis()" | |
# setup roxygen | |
Rscript --no-save -e "devtools::use_package_doc()" | |
# do this last to get reminder msg | |
#Rscript --no-save -e "devtools::use_code_of_conduct()" | |
# add config opts to .Rproj | |
# add test scaffold | |
cat <<EOF >tests/testthat/test-$PACKAGENAME.R | |
context("basic functionality") | |
test_that("we can do something", { | |
#expect_that(some_function(), is_a("data.frame")) | |
}) | |
EOF | |
# enhance README.Rmd | |
cat <<EOF >>README.Rmd | |
[![Build Status](https://travis-ci.org/$HANDLE/$PACKAGENAME.svg)](https://travis-ci.org/$HANDLE/$PACKAGENAME) | |
[![Project Status: Concept - Minimal or no implementation has been done yet.](http://www.repostatus.org/badges/0.1.0/concept.svg)](http://www.repostatus.org/#concept) | |
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/$PACKAGENAME)](http://cran.r-project.org/web/packages/$PACKAGENAME) | |
![downloads](http://cranlogs.r-pkg.org/badges/grand-total/$PACKAGENAME) | |
$PACKAGENAME is ... | |
The following functions are implemented: | |
The following data sets are included: | |
### News | |
- Version `` released | |
### Installation | |
\`\`\`{r, eval=FALSE} | |
devtools::install_github("$HANDLE/$PACKAGENAME") | |
\`\`\` | |
\`\`\`{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE} | |
options(width=120) | |
\`\`\` | |
### Usage | |
\`\`\`{r, eval=FALSE} | |
library($PACKAGENAME) | |
# current verison | |
packageVersion("$PACKAGENAME") | |
\`\`\` | |
### Test Results | |
\`\`\`{r, eval=FALSE} | |
library($PACKAGENAME) | |
library(testthat) | |
date() | |
test_dir("tests/") | |
\`\`\` | |
EOF | |
# add makefile | |
cat <<EOF >>makefile | |
LFILE = README | |
all: knith open | |
knith: \$(LFILE).Rmd | |
echo "rmarkdown::render('\$(LFILE).Rmd',output_file='\$(LFILE).html')" | R --no-save -q | |
knitr: \$(LFILE).Rmd | |
echo "rmarkdown::render('\$(LFILE).Rmd',rmarkdown::md_document(variant='markdown_github'))" | R --no-save -q | |
open: \$(LFILE).html | |
xdg-open \$(LFILE).html & | |
clean: | |
rm -rf *.html *.png README_cache | |
EOF | |
# until R is updated... | |
cat <<EOF >>.Rbuildignore | |
^README\.md$ | |
^makefile$ | |
EOF | |
# finish roxygen setup | |
Rscript --no-save -e "devtools::document(roclets=c('rd', 'collate', 'namespace'))" | |
# default build to avoid inital README githook warning | |
Rscript --no-save -e "devtools::build()" | |
# but then remove .tar.gz | |
rm ../$PACKAGENAME'_0.0.0.9000.tar.gz' | |
# build initial README.md | |
Rscript --no-save -e "knitr::knit('README.Rmd')" | |
# add components to git | |
git add DESCRIPTION NAMESPACE README.Rmd README.md LICENSE | |
git add R/$PACKAGENAME-package.r | |
git add man/$PACKAGENAME.Rd | |
git add tests/testthat.R | |
git add tests/testthat/test-$PACKAGENAME.R | |
git add .travis.yml .Rbuildignore | |
echo "------------------------------------" | |
echo "NOW: Modify DESCRITPION to License: GPL-3 + file LICENSE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment