#' necessary.packages #' checks if a particular package is installed if not then it installs and loads. #' @param pkg vector containing names of the packegs required to be loaded #' @export necessary.packages<-function(pkg){ for( i in 1:length(pkg)){ if((pkg[i] %in% rownames(installed.packages()))){ print(paste("Package ", pkg[i], " is already installed")) } if(!(pkg[i] %in% rownames(installed.packages()))){ print(paste("Need to install the package", pkg[i])) install.packages(pkg[i]) } } } necessary.packages(c("MASS", "Matrix", "pscl","distr","rstiefel")) library(MASS) library(Matrix) library(pscl) library(distr) library(rstiefel)