Last active
August 29, 2015 14:23
-
-
Save hrbrmstr/fd4103af960b8bd8fdb4 to your computer and use it in GitHub Desktop.
Initialize everything (basically) necessary for a new (non-Rcpp) R package. Now with devtools goodness. You should setup DEV_HOME, AUTNAME, HANDLE and also set up those additions to your .Rprofile. NOTE that it also opens RStudio via "open" if on a Mac. Run as "newpkg PKGNAME"
This file contains hidden or 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 | |
# AUTHOR: Bob Rudis <[email protected]> (@hrbrmstr) | |
# LICENSE: MIT + file zLICENSE | |
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=~/Development | |
# | |
# author name | |
AUTNAME="Bob Rudis" | |
# travis/github/etc handle | |
HANDLE=hrbrmstr | |
# | |
############################ | |
# start pkg setup | |
# note that this adds a .Rproj, R dir and DESCRIPTION + other stuff | |
Rscript --no-save -e "devtools::create('$DEV_HOME/$PACKAGENAME', rstudio=TRUE)" | |
cd $DEV_HOME/$PACKAGENAME | |
cat <<EOF >LICENSE | |
YEAR: $YEAR | |
COPYRIGHT HOLDER: $AUTNAME | |
EOF | |
# setup git | |
Rscript --no-save -e "devtools::use_git()" | |
# add README.Rmd | |
Rscript --no-save -e "devtools::use_readme_rmd('$DEV_HOME/$PACKAGENAME')" | |
# 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 | |
cat <<EOF >>$PACKAGENAME.Rproj | |
UseSpacesForTab: Yes | |
NumSpacesForTab: 2 | |
RnwWeave: Sweave | |
LaTeX: pdfLaTeX | |
PackageBuildArgs: --resave-data | |
PackageCheckArgs: --as-cran | |
EOF | |
# add base package R file | |
cat <<EOF >R/$PACKAGENAME-package.R | |
#' A package to ... | |
#' @name $PACKAGENAME | |
#' @docType package | |
#' @author $AUTNAME (@@$HANDLE) | |
# @import httr dplyr stringr devtools | |
# @importFrom Rcpp evalCpp | |
# @useDynLib $PACKAGENAME | |
# @exportPattern ^[[:alpha:]]+ | |
NULL | |
EOF | |
# 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 | |
[](https://travis-ci.org/$HANDLE/$PACKAGENAME) | |
](http://www.repostatus.org/#concept) | |
[](http://cran.r-project.org/web/packages/$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} | |
library($PACKAGENAME) | |
# current verison | |
packageVersion("$PACKAGENAME") | |
\`\`\` | |
### Test Results | |
\`\`\`{r} | |
library($PACKAGENAME) | |
library(testthat) | |
date() | |
test_dir("tests/") | |
\`\`\` | |
### Code of Conduct | |
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). | |
By participating in this project you agree to abide by its terms. | |
EOF | |
# roxygen complains if this is populated | |
>NAMESPACE | |
# until R is updated... | |
cat <<EOF >>.Rbuildignore | |
^README\.md$ | |
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()" | |
# build initial README.md | |
Rscript --no-save -e "knitr::knit('README.Rmd')" | |
# Open RStudio with said package | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
# I'm on a Mac so I do this. RStudio doesn't always obey the first call | |
# but also really doesn't like it if there's already a proj window open | |
open $PACKAGENAME.Rproj | |
sleep 1 | |
ct=`ps -ef | grep -v grep | grep -c "$PACKAGENAME.Rproj"` | |
if [ ct == 0 ]; then | |
open $PACKAGENAME.Rproj | |
fi | |
fi |
This file contains hidden or 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
options(devtools.name = "Bob Rudis", | |
devtools.desc.author = 'c(person("Bob", "Rudis", email = "[email protected]", role = c("aut", "cre")))', | |
devtools.desc.license = "MIT + file LICENSE") |
This file contains hidden or 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
The MIT License (MIT) | |
Copyright (c) <year> <copyright holders> | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment