An R package is a collection of functions that have a shared purpose. Installing base R comes with existing core packages (e.g. stats), and tens of thousands on additional packages on additional code repositories CRAN, GitHub, Bioconductor.
We’re often using other people packages (every time we use library) so we should think about developing our own package if one doesn’t already exist and we’ll be reusing or sharing the code with others.
Aim: The aim of the presentation today is to provide the simplest workflow to take a collection of existing functions and turn them into an R package.
Why develop an R package? (1)
Collects shared code/functions in a single source
Modularises code
Easier to re-use individual components
Easier to maintain
Encourages best practice
Documentation
File Structure
Validation
Why develop an R package? (2)
Easier to share and collaborate
Defined processes and structure
Can store of code repositories
Scaleable
KerusCore is an R package run on AWS
DMB is an R package deployed in a Container on AWS
Allows access to other tools/services
Unit testing
Continuous Integration/ Development
What does an R Package consist of?
Description File
This contains meta-data about the package
Package: mypackage
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R:
person("First", "Last", , "first.last@example.com", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph)
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
license
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
# Function to test values are a whole number#' @title Function to test if values are an integer#' @name IsWholeNumber#' @param values A vector of numeric values#' @param tolerance The level at to estimate floating-point comparisons for integer#' @rdname IsWholeNumber#' @author Gareth Burns#' @exportIsWholeNumber <-function(values, tolerance = .Machine$double.eps^0.5) {abs(values -round(values)) < tolerance }
Build the package into a source / tar file. This can be done using RStudio
Build > More > Build Source Package
Put the tar file in a shared network location or email to collaborator. Users can either download the tar file and then install the package, or install the package directly from the compressed folder on the shared drive