Deciphering life: One bit at a time

Robert M Flight's home on the web

Portable, personal packages

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

Tagged in: R, packages
Posted on 2013-09-23
comments powered by Disqus