Installing an R Package if Required

When you have serveral packages for your code and you dont know which are already installed a good way to do this programatically is as follows.

list.of.packages <- c(“package1”, “package2”, “package3”)
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,”Package”])]
if(length(new.packages)) install.packages(new.packages)

Referenced from here.

Leave a comment