library(desc)
shared_path <- "/shared/earth/software/R/3.6.1-foss-2015a-bare/lib64/R/library/"
fields_to_get <- c("Package", "Version", "License", "SystemRequirements",
                   "Depends", "Imports")
# package alpahbetical order: first direct dependencies, then subdependencies:
packages <- list("multiApply",   "chron", "RNetCDF", "dplyr", "magrittr",
                 "openair", "plotly", "plyr", "raster", "reshape2",
                 "rgdal", "rgeos", 
                 "scales", "sf", "sp", "yaml", "timeDate","compiler",
             # Dependencies
                  "doParallel", "foreach", "graphics", "stats", 
                  "ellipsis", "generics", "glue", "lifecycle",
 "tibble", "tidyselect", "utils", "vctrs", "grid", "rlang", "purrr", "tidyr", "readr", "mgcv",
 "latticeExtra", "lubridate", "cluster", "mapproj", "hexbin",
  "grDevices", "methods", "MASS",
  "ggplot2", "tools", "httr", "jsonlite", "digest",
  "base64enc", "htmltools", "htmlwidgets", "RColorBrewer", "lazyeval",
  "crosstalk", "data.table", "promises", "Rcpp", "stringr", 
  "units", "classInt", "DBI", #"sqlite3",
  "labeling", "R6","viridisLite", "munsell",
  #Sub-dependencies
  "iterators", "codetools",
  "cli", "crayon", "fansi", "pillar", "stringi", "hms", "clipr",
  "Matrix", "splines", "nlme", "gtable", "withr", 
  "curl", "mime", "openssl", "shiny",
  "e1071", "class", "KernSmooth", "colorspace", 
  # Sub-sub-dependencies
  "assertthat", "utf8",
  "pkgconfig", "askpass", "httpuv", "fastmap",
  "xtable", "sourcetools", "later",
  # sub-sub-sub
  "sys")

packages[duplicated(packages)]

# Packages that are not installed but they still working because they are suggestions: R.rsp, rnaturalearth

info <- lapply(packages, function(pck) {
               desc_get(fields_to_get, file = paste0(shared_path, pck))})

info <- plyr::ldply(info, rbind)

write.table(info, "/esarchive/scratch/nperez/urbanR_Portability.csv", sep = ",", row.names =F)

print(info)

