Portable, Personal Packages

My take on creating simple little packages for your own commonly used functions.

R
packages
development
Author

Robert M Flight

Published

September 23, 2013

ProgrammingR had an interesting post recently about keeping a set of R functions that are used often as a gist on Github, and sourceing that file at the beginning of R analysis scripts. There is nothing inherently wrong with this, but it does end up cluttering the user workspace, and there is no real documentation on the functions, and no good way to implement unit testing.

However, the best way to have sets of R functions is as a package, that can then be installed and loaded by anyone. Normally packages are compiled and hosted on CRAN, R-forge, or Bioconductor. However, Github is becoming a common place to host packages, and thanks to Hadley Wickham’s install_github function in the devtools package, it is rather easy to install a package directly from Github. This does require that you have r-tools installed if you are using Windows (I know that can take a bit of work, but it’s not impossible), and do some extra work to create a proper package, but the overhead is probably worth it if you are using these functions all the time.

Once you have the package created and hosted on Github, it is simple to install it once, and load it when needed. If there is a particular version of the package that is required, it is even possible to tell install_github to install a particular version based on the commit, or a tag.

Some examples of this type of package can be found on Github: 1 2 3

Reuse

Citation

BibTeX citation:
@online{mflight2013,
  author = {Robert M Flight},
  title = {Portable, {Personal} {Packages}},
  date = {2013-09-23},
  url = {https://rmflight.github.io/posts/2013-09-23-portable-peronal-packages},
  langid = {en}
}
For attribution, please cite this work as:
Robert M Flight. 2013. “Portable, Personal Packages.” September 23, 2013. https://rmflight.github.io/posts/2013-09-23-portable-peronal-packages.