ipak.R 1.7 KB

1234567891011121314151617181920
  1. # ipak function: install and load multiple R packages.
  2. # check to see if packages are installed. Install them if they are not, then load them into the R session.
  3. chooseCRANmirror(graphics=FALSE, ind=8)
  4. ipak <- function(pkg){
  5. new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
  6. if (length(new.pkg))
  7. install.packages(new.pkg, dependencies = TRUE)
  8. sapply(pkg, require, character.only = TRUE)
  9. }
  10. # usage
  11. packages <- c("ggplot2", "plyr", "reshape2", "RColorBrewer", "scales", "grid", c("plyr","digest","ggplot2","colorspace","stringr","RColorBrewer","reshape2","zoo","proto","scales","car","dichromat","gtable","munsell","labeling","Hmisc","rJava","mvtnorm","bitops","rgl","foreign","XML","lattice","e1071","gtools","sp","gdata","Rcpp","MASS","Matrix","lmtest","survival","caTools","multcomp","RCurl","knitr","xtable","xts","rpart","evaluate","tseries","DBI","nlme","lme4","reshape","sandwich","leaps","gplots","abind","randomForest","Rcmdr","coda","maps","igraph","formatR","maptools","RSQLite","psych","KernSmooth","rgdal","RcppArmadillo","effects","sem","vcd","XLConnect","markdown","timeSeries","timeDate","RJSONIO","cluster","scatterplot3d","nnet","fBasics","forecast","quantreg","foreach","chron","plotrix","matrixcalc","aplpack","strucchange","iterators","mgcv","kernlab","SparseM","tree","robustbase","vegan","devtools","latticeExtra","modeltools","xlsx","slam","TTR","quantmod","relimp","akima","memoise","classInt","pander", "rmarkdown", "shiny"))
  12. packages2 <- c("RODBC", "sf","velox","geoRglm","RandomFields","RandomFieldsUtils","Hmisc","gdistance","fANCOVA","shp2graph","lidR","RPostgreSQL","nloptr","devtools","rmapshaper","spatialEco")
  13. ipak(packages)
  14. #ipak(packages2)