R/install_gshhg.R

Defines functions install_gshhg

Documented in install_gshhg

#' Download and Install GSHHG Binary Data
#' 
#' This is a function for downloading and installing the latest version of the
#' GSHHG binary dataset. Current version supported is 2.3.7. This only needs
#' to be run once after the package is installed. 
#'
#' @return NULL
#' @importFrom utils download.file unzip 
#' @export
#'
install_gshhg <- function() {
  if (!dir.exists(system.file("extData", package = "ptolemy"))) {
    dir.create(system.file("extData", package = "ptolemy"))
  }
  data_path <- system.file("extData", package = "ptolemy")
  
  if (!file.exists(paste(data_path, "gshhg-bin-2.3.7", sep = "/"))) {
    cont <- readline(
      prompt = "Download and install source gshhg data (Y,n)? "
    )
    if (cont == "Y") {
      op <- getOption("timeout")
      options(timeout = max(600, getOption("timeout")))
      tmp <- tempfile(fileext = ".zip")
      download.file(
        "https://www.ngdc.noaa.gov/mgg/shorelines/data/gshhg/latest/gshhg-bin-2.3.7.zip",
        tmp
      )
      unzip(tmp, 
            exdir = paste(data_path, 
                          "gshhg-bin-2.3.7", 
                          sep = "/"))
      unlink(tmp)
      options(timeout = op)
    } else if (cont == "n") {
      message("Source data will not be downloaded")
    } else {
      message("You must respond with Y or n")
    }
  } else {
    message("Source data already installed")
  }
}
jmlondon/nPacMaps documentation built on Nov. 6, 2021, 4:04 p.m.