Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. # ipak function: install and load multiple R packages.
  2. # Check to see if packages are installed. Install them if they are not.
  3. # Optionally, load them into the R session.
  4.  
  5. ipak <- function(pkg, load = FALSE){
  6. new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
  7. if (length(new.pkg)) {
  8. install.packages(new.pkg, dependencies = TRUE)
  9. }
  10. update.packages(ask = FALSE)
  11. if(load){
  12. sapply(pkg, require, character.only = TRUE)
  13. }
  14. }
  15.  
  16. # usage
  17. packages <- c(
  18. "assertthat", "testthat", "devtools", "dplyr",
  19. "readxl", "reshape2", "ggplot2", "stringr", # Hadley-verse
  20. "jsonlite", "knitr", "yaml", "xml2", "lubridate", # Utils
  21. "lamW", "bbmle", "boot", "emdbook", # FRAIR
  22. "sp", "spatial", "gstat", "maps", "maptools", "leaflet", # GIS
  23. "MASS", "vegan", "car", "nortest", # Statistics
  24. "RColorBrewer", "cowplot", "ggthemes", # Plotting
  25. "fortunes" # Fun
  26. )
  27.  
  28. ipak(packages, load = FALSE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement