Skip to content

Instantly share code, notes, and snippets.

@mathzero
Last active May 10, 2020 18:04
Show Gist options
  • Save mathzero/d37575dbca2dc87dee14a2ab2df2a8e7 to your computer and use it in GitHub Desktop.
Save mathzero/d37575dbca2dc87dee14a2ab2df2a8e7 to your computer and use it in GitHub Desktop.
Snippet of code to include at start of a script to install and load any necessary packages
### Install packages
list.of.packages <- c("citr", "colourpicker", "rcrossref", "jpeg","RCurl") ### add all the packages that are used in your script here
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] ### check if they are installed
if(length(new.packages)) install.packages(new.packages) ### install any that need installing
### Load packages
lapply(list.of.packages, require, character.only = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment