# Rscript r_install.R

EBROOTELIC_R <- Sys.getenv("EBROOTELIC_R")

packages = c('leaflet', 'satellite', 'MuMIn', 'intervals', 'spacetime', 'gstat', 'automap', 'reporttools', 'rgeos', 'RandomFieldsUtils', 'RandomFields', 'rworldmap', 'colorRamps', 'mapdata', 'mapproj', 'RPostgreSQL', 'getPass', 'stringdist', 'here', 'svMisc', 'networkD3', 'nzelect', 'wordcloud', 'ngram', 'rtweet', 'xgboost', 'rts', 'RgoogleMaps', 'packrat', 'rsconnect', 'rpostgis', 'aws.signature', 'aws.s3', 'geosphere', 'fuzzyjoin', 'refinr', 'x13binary', 'seasonal', 'mitools', 'survey', 'sysfonts', 'showtextdb', 'showtext', 'BiocManager', 'rvcheck', 'scatterpie', 'rlist', 'measurements', 'qpdf', 'fda', 'fda.usc', 'gstat', 'countrycode', 'itcSegment', 'owmr', 'rwunderground', 'corrplot', 'prettymapr', 'prospectr', 'rpart.plot', 'varhandle', 'expint', 'actuar', 'psych', 'plotly', 'spatstat', 'raster', 'treemap', 'ggmap', 'hts', 'thief', 'forecastHybrid', 'ggseas', 'colourpicker', 'profvis', 'jsonlite', 'readxl', 'tidyverse', 'data.table', 'lubridate', 'stringi', 'snakecase', 'Matrix', 'RSelenium', 'devtools', 'ggplot2', 'metR', 'raster', 'rgeos' , 'sp' , 'rgdal' , 'rmapshaper' ,'adehabitatMA', 'maptools', 'plyr' , 'dplyr' , 'tmap', 'tmaptools', 'reshape', 'ggplot2', 'png')

## Now load or install&load all
package.check <- lapply(
  packages,
  FUN = function(x) {
    if (!require(x, character.only = TRUE)) {
      install.packages(x, repos='https://www.freestatistics.org/cran/', lib=EBROOTELIC_R)
      library(x, character.only = TRUE)
    }
  }
)
