## If a package is installed, it will be loaded. If any 
## are not, the missing package(s) will be installed 
## from CRAN and then loaded.

## First specify the packages of interest
packages = c('leaflet', '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', 'shinyFiles', 'shinyhelper', 'shinycssloaders', 'shinyWidgets', 'shinyBS', 'svglite', 'rworldxtra', 'parallel', 'gdtools', 'mapview', 'RNetCDF', 'clhs', 'cmsaf', 'RPostgres', 'satellite')

## 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='/opt/easybuild/soft/2024a/software/R-bundle-CRAN/2024.11-foss-2024a')
      library(x, character.only = TRUE)
    }
  }
)
