Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ipak function: install and load multiple R packages.
- # Check to see if packages are installed. Install them if they are not.
- # Optionally, load them into the R session.
- ipak <- function(pkg, load = FALSE){
- new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
- if (length(new.pkg)) {
- install.packages(new.pkg, dependencies = TRUE)
- }
- update.packages(ask = FALSE)
- if(load){
- sapply(pkg, require, character.only = TRUE)
- }
- }
- # usage
- packages <- c(
- "assertthat", "testthat", "devtools", "dplyr",
- "readxl", "reshape2", "ggplot2", "stringr", # Hadley-verse
- "jsonlite", "knitr", "yaml", "xml2", "lubridate", # Utils
- "lamW", "bbmle", "boot", "emdbook", # FRAIR
- "sp", "spatial", "gstat", "maps", "maptools", "leaflet", # GIS
- "MASS", "vegan", "car", "nortest", # Statistics
- "RColorBrewer", "cowplot", "ggthemes", # Plotting
- "fortunes" # Fun
- )
- ipak(packages, load = FALSE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement