Guest User

Untitled

a guest
Aug 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 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, then load them into the R session.
  3.  
  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.  
  11. # usage
  12. packages <- c("ggplot2", "plyr", "reshape2", "RColorBrewer", "scales", "grid")
  13. ipak(packages)
Add Comment
Please, Sign In to add comment