Last active
August 5, 2021 11:03
-
-
Save ArnauMontagud/a2d3270c9e670cb6a2bac76310e93278 to your computer and use it in GitHub Desktop.
[R Check for missing packages and install them] Place at the beginning of the R script to check for missing packages and install them (and only in option2 load them) #R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from: https://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them | |
# This checks for missing packages and installs them. You will need to load them manually | |
list.of.packages <- c("ggplot2", "magrittr") | |
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] | |
if(length(new.packages)) install.packages(new.packages) | |
# library(ggplot2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This checks for missing packages, installs them and loads them. | |
if (!require("pacman")) install.packages("pacman") | |
list.of.packages <- c("ggplot2", "magrittr") | |
pacman::p_load(list.of.packages, character.only = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment