R/zzz.R

Defines functions .onLoad .onAttach depthList

#' @useDynLib rasterTools
#' @importFrom utils packageVersion data globalVariables

# startup mesages ----
.onLoad <- function(...) {
  pathFile <- paste0(.libPaths()[1], "/rasterTools/data/rtPaths.rda")

  if(!file.exists(pathFile)){
    rtPaths <- list(root = NA,
                    project = NA,
                    clc = list(local = NA,
                               remote = "missing"),
                    emma = list(local = NA,
                                remote = "https://www.european-mammals.org/php/rendermap.php?latname=",
                                gridLinks = "http://www.helsinki.fi/~rlampine/gmap/gridfilelinks.kml"),
                    efta = list(local = NA,
                                remote = "https://w3id.org/mtv/FISE/map-data"),
                    esalc = list(local = NA,
                                 remote = "ftp://geo10.elie.ucl.ac.be/v207/",
                                 qualityLayer = "https://storage.googleapis.com/cci-lc-v207/ESACCI-LC-L4-LCCS-Map-300m-P1Y-1992_2015-v2.0.7_Qualityflags.zip"),
                    gfc = list(local = NA,
                               remote = "http://commondatastorage.googleapis.com/earthenginepartners-hansen/GFC2015/"),
                    modis = list(local = NA,
                                 remote = "https://e4ftl01.cr.usgs.gov/"),
                    sentinel = list(local = NA,
                                    remote = "missing"),
                    worldclim = list(local = NA,
                                     remote = "http://biogeo.ucdavis.edu/data/")
    )
  } else{
    load(pathFile)
  }

  options(rtPaths = rtPaths)

  invisible()
}

.onAttach <- function(...) {
  pathFile <- paste0(.libPaths()[1], "/rasterTools/data/rtPaths.rda")
  assign("rtPaths", getOption("rtPaths"), envir = as.environment("package:rasterTools"))
  if(!file.exists(pathFile)){
    packageStartupMessage(paste0("I don't know where your files are stored, please see '?setPaths' to create a suitable index."))
  }
  invisible()
}

# internal objects and functions ----
globalVariables(c("rtPaths", "rtRasters", "rtTheme", "rtMD5", "rtGeoms", "rtSP"))
# meta data
globalVariables(c("meta_modis", "meta_clc", "meta_emma", "meta_efta", "meta_esalc", "tiles_emma"))
# projections
globalVariables(c("projs"))
# some subsetting variables
globalVariables(c("sbst", "selected"))

depthList <- function(list) {
  ifelse(is.list(list), 1L + max(sapply(list, depthList)), 0L)
}

listArgs <- function (){
  as.list(
    match.call(
      definition = sys.function( -1 ),
      call = sys.call( -1 )
    )
  )[-1]
}
EhrmannS/rasterTools documentation built on Sept. 4, 2019, 10:34 a.m.