R/misc.R

  #' Test for the existence of a OBPG_PATH
#'
#' @export
#' @param path the path to test
#' @return named logical, TRUE of the path exists
#' @examples{
#'  \dontrun{
#'      has_obpg()
#'  }
#'  }
has_obpg <- function(path){
   sapply(path, dir.exists)
}

#' Retrieve the OBPG path
#'
#' @export
#' @param root_path the root path - defaults to the currently correct path
#' @param ... further arguments for \code{file.path(path, ...)}
#' @return character path description
obpg_path <- function( ..., root_path = "/mnt/ecocast/coredata/obpg") {
   ok <- has_obpg(root_path)
   if (!ok){
      stop("unable to find root obpg data path:", root_path)
   } else {
      r <- file.path(root_path[1], ...)
   }
   r
}


#' Various bounding boxes
#'
#' @export
#' @param what character 'native' (entire earth), 'gom', 'nwna', etc
#' @return 4 element vector of [left, right, bottom, top]
obpg_bb <- function(what = c('native', 'gom')[2]){
    #switch(tolower(what[1]),
    #    'gom' = c(-72,-63,39,46),
    #    'nwa' = c(-77.1199677903564, -51.6967983980479,
    #        37.9115974449456, 56.6768926463509),
    #    c(-180, 180, -90, 90))
    celmap::get_bb(what)
}
BigelowLab/obpgtools documentation built on May 5, 2019, 2:44 p.m.