library(packageSkeletonForR) is_html_output = function() { knitr::opts_knit$get("rmarkdown.pandoc.to")=="html" } knitr::opts_chunk$set( collapse = TRUE, comment = "", prompt=TRUE, fig.dpi = 96 ) if (is_html_output()) { options(width=1000) }
The packageSkeletonForR is both a GitHub version control repository, and associated GitHub hosted static website as well as an R package. The combination of GitHub and R together is a super-power skill to develop if you have a serious interest in data analysis.
The following steps are meant to help you get set up:
You'll need to have software installed and access to GitHub to make all of this work.
update.packages(ask=FALSE)
install.packages("devtools")
devtools::install_github("centerforassessment/packagePages")
devtools::install_github("centerforassessment/centerPackageTemplate")
The contents of this repo need to be cloned to your local computer/device. This is done by cloning the repo. Don't fork the repo as you won't be contributing to this package skeleton (at least I don't expect you will --- however that's OK too) but instead will be using this as a starting point to create your own customzed R package/GitHub repo that will, ideally, be quite different. If you're using RStudio, there are some easy to follow directions on how to integrate RStudio with GitHub and, among many other things, clone a repo.
Once you have cloned the packageSkeletonForR repo, you need to create a repo in your personal (or institutional) GitHub page that will house your
modified version of this package skeleton. Go to your GitHub page and look for the repositories
tab toward the top and click on the new
button to
start creating a new repo that will house the source code for your R package. Here's a screenshot from my initial setup:
The packageSkeletonForR package is a super simple R package that contains just two functions for illustration purposes: strHead
and strTail
.
These two functions take two arguments (string
and n_char
) and take the first n_char characters off the head or tail of the string
(or a
vector of character strings), respectively. They are the analogs of the R functions head
and tail
but for strings. You're welcome to keep these functions or remove them.
Some things you should do:
packageSkeletonForR
to something you want (in these instructions we'll call is myPackageName
). Throughout the package change any occurrence of packageSkeletonForR
to the name you pick.NAMESPACE
(export the function) and document the function in the man
(manual) folder. Examine the current NAMESPACE
and man
folder contents to see how that is done.NEWS.md
and NEWS
files indicating changes to the package. NEWS.md is used for the static website and, ideally, will just be a copy of NEWS
.vignettes
folder. Use the basic vignette that you're reading now (packageSkeletonForR.Rmd
) in the folder as a starter.DESCRIPTION
, inst/CITATION
, man/packageSkeletonForR.Rmd
(last file should be named the package name you picked).To help illustrate what all these changes would look like, I've cloned the packageSkeletonForR and modified it and created a customized version of it called customizedPackageForR:
Once you get your package tidied up with name changes and customizations, to make sure everything is working build your package locally. If you're using RStudio, there are capabilities to build the package included in the user interface. If you are using OSX or Windows you will likely be using the command line to build, check, and install your package locally.
You'll need to create a GitHub repo in your account for myPackageName
.
GitHub is rapidly evolving into much more than a website to do version control. For each repo, one can set up:
Another huge benefit of using GitHub to build your package is that you can immediately share your package with others without necessarily posting the package to CRAN. packageSkeletonForR is a functional R package and can be installed from GitHub just like any other R package via:
devtools::install_github("CenterForAssessment/packageSkeletonForR")
or
remotes::install_github("CenterForAssessment/packageSkeletonForR")
Once you get the package set up in your own repository, your package will be able to be installed similarly. In our work we have functional development versions of the package available via GitHub and periodically post a big release version on CRAN just to keep that up-to-date.
The packageSkeletonForR Package is crafted with love by:
I love feedback and am happy to answer questions. Feel free to clone and make a pull request with the specifications for other languages.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.