##########################################
# List of useful epidemiology R packages #
##########################################
# This script uses the p_load() function from pacman R package,
# which installs if package is absent, and loads for use if already installed
# Ensures the package "pacman" is installed
if (!require("pacman")) install.packages("pacman")
# Packages available from CRAN
##############################
::p_load(
pacman
# learning R
############
# interactive tutorials in RStudio Tutorial pane
learnr, # interactive tutorials in R console
swirl,
# project and file management
#############################
# file paths relative to R project root folder
here, # import/export of many types of data
rio, # import/export of multi-sheet Excel workbooks
openxlsx,
# package install and management
################################
# package install/load
pacman, # managing versions of packages when working in collaborative groups
renv, # install from github
remotes,
# General data management
#########################
# includes many packages for tidy data wrangling and presentation
tidyverse, #dplyr, # data management
#tidyr, # data management
#ggplot2, # data visualization
#stringr, # work with strings and characters
#forcats, # work with factors
#lubridate, # work with dates
#purrr # iteration and working with lists
# cleaning linelists
linelist, # assessing missing data
naniar,
# statistics
############
# tables and data cleaning
janitor, # making descriptive and statistical tables
gtsummary, # quickly run statistical tests and summaries
rstatix, # tidy up results from regressions
broom, # likelihood-ratio tests
lmtest,
easystats,# parameters, # alternative to tidy up results from regressions
# see, # alternative to visualise forest plots
# epidemic modeling
###################
# Analysing transmission networks
epicontacts, # Rt estimation
EpiNow2, # Rt estimation
EpiEstim, # Incidence projections
projections, # Make epicurves and handle incidence data
incidence2, # Extra functions for the incidence2 package
i2extras, # Useful epi functions
epitrix, # Discrete delay distributions
distcrete,
# plots - general
#################
#ggplot2, # included in tidyverse
# combining plots
cowplot, # patchwork, # combining plots (alternative)
# color scales
RColorBrewer, # to add additional layers of color schemes
ggnewscale,
# plots - specific types
########################
# diagrams using DOT language
DiagrammeR, # epidemic curves
incidence2, # highlight a subset
gghighlight, # smart labels
ggrepel, # interactive graphics
plotly, # animated graphics
gganimate,
# gis
######
# to manage spatial data using a Simple Feature format
sf, # to produce simple maps, works for both interactive and static maps
tmap, # to add OSM basemap in ggplot map
OpenStreetMap, # spatial statistics
spdep,
# routine reports
#################
# produce PDFs, Word Documents, Powerpoints, and HTML files
rmarkdown, # auto-organization of R Markdown outputs
reportfactory, # powerpoints
officer,
# dashboards
############
# convert an R Markdown script into a dashboard
flexdashboard, # interactive web apps
shiny,
# tables for presentation
#########################
# R Markdown report generation and html tables
knitr, # HTML tables
flextable, #DT, # HTML tables (alternative)
#gt, # HTML tables (alternative)
#huxtable, # HTML tables (alternative)
# phylogenetics
###############
# visualization and annotation of trees
ggtree, # analysis of phylogenetics and evolution
ape, # to visualize phylogenetic files
treeio
)
5 Suggested packages
Below is a long list of suggested packages for common epidemiological work in R. You can copy this code, run it, and all of these packages will install from CRAN and load for use in the current R session. If a package is already installed, it will be loaded for use only.
You can modify the code with #
symbols to exclude any packages you do not want.
Of note:
- Install the pacman package first before running the below code. You can do this with
install.packages("pacman")
. In this handbook we emphasizep_load()
from pacman, which installs the package if necessary and loads it for use in the current R session. You can also load packages that are already installed withlibrary()
from base R.
- In the code below, packages that are included when installing/loading another package are indicated by an indent and hash. For example how ggplot2 is listed under tidyverse.
- If multiple packages have functions with the same name, masking can occur when the function from the more recently-loaded package takes precedent. Read more in the R basics page. Consider using the package conflicted to manage such conflicts.
- See the R basics section on packages for more information on pacman and masking.
To see the versions of R, RStudio, and R packages used during the production of this handbook, see the page on Editorial and technical notes.
5.1 Packages from CRAN
5.2 Packages from Github
Below are commmands to install two packages directly from Github repositories.
- The development version of epicontacts contains the ability to make transmission trees with an temporal x-axis
- The epirhandbook package contains all the example data for this handbook and can be used to download the offline version of the handbook.
# Packages to download from Github (not available on CRAN)
##########################################################
# Development version of epicontacts (for transmission chains with a time x-axis)
::p_install_gh("reconhub/epicontacts@timeline")
pacman
# The package for this handbook, which includes all the example data
::p_install_gh("appliedepi/epirhandbook") pacman