Department of Biostatistics Seminar/Workshop Series
R Package Development with GitHub
Cole Beck, B.S.
Computer Systems Analyst, Department of Biostatistics
The motivation for writing an R package is to make your code available. Often this is done by contributing the package to the CRAN package repository. In this seminar we will consider an alternative method, hosting your package on GitHub and distributing via devtools. This will include a brief overview of the packages roxygen2 and testthat.
Package development cheatsheet
Prepare System
install.packages(c("devtools", "roxygen2", "testthat", "knitr"))
library(devtools)
has_devel()
Write Package
wd <- file.path('~','packages','miscpackage')
devtools::create(wd)
# modify DESCRIPTION
# add code
# add documentation
devtools::document()
# vignette VS URL
# add tests
devtools::use_testthat()
Additional components to consider:
Use Git (Local)
# create local Git repository
git init
# consider adding README
touch README.md
# stage everything
git add .
# commit to history
git commit -m "first commit"
Use GitHub (Remote)
- Create user on GitHub
- Create new repository
# from your working directory, let local repo know about remote repo
git remote add origin https://github.com/GitHubUserName/RepoName.git
# push local to remote
git push -u origin master
Install Package
library(devtools)
install_github("GitHubUserName/RepoName")
Learn more:
http://r-pkgs.had.co.nz/intro.html