July 16, 2019

Creating Packages in R -
Outline

  1. Philosophy
  2. Package Structure
  3. Automatization
  4. Literature
  5. Package Creation - Hands on

Philosophy I - What are R packages?

R packages are collections of functions and data sets developed by the community. They increase the power of R by improving existing base R functionalities, or by adding new ones.
A package is a suitable way to organize your own work and, if you want to, share it with others. Typically, a package will include code (not only R code!), documentation for the package and the functions inside, some tests to check everything works as it should, and data sets.



Philosophy II - Effective Package programming

  • Anything that can be automated, should be automated
  • Do as little as possible by hand
  • Do as much as possible with functions
  • The goal is to spend your time thinking about what you want your package to do rather than thinking about the minutiae of package structure.

Philosophy III - Package hosts

Packages can be deployed basically everywhere. The most used ways to deploy Packages are:

  • Locally
  • Github/ Githlab repositories
  • Official Package Repositories (CRAN, Bioconductor)

Package Structure I - Features

The Structure of an R-package is usually divided in multiple Files and Folders. There are some Rules that we have to Follow when using a Package properly



Package Structure II - Examplary Structure

Here is one Example from one of my own Packages:

Package Structure III - Lifecycle

To master package development, particularly when you’re distributing a package to others, it really helps to understand the five states a package can be in across its lifecycle:

  • source: What we’ve seen so far
  • bundled: compressed into a single file. By convention (from Linux), package bundles in R use the extension .tar.gz. This means that multiple files have been reduced to a single file (.tar) and then compressed using gzip (.gz).
  • binary: If you want to distribute your package to an R user who doesn’t have package development tools, you’ll need to make a binary package. Like a package bundle, a binary package is a single file but has a much more efficient architecture
  • installed: An installed package is just a binary package that’s been decompressed into a package library.
  • in-memory: To use a package, you must load it into memory. R loads packages automatically when you use library.

Automatization I - Package vs Function