R/checkCoords.R

Defines functions checkCoords

Documented in checkCoords

#' @title \emph{checkCoords}: function used to check coordinate names.
#' @description An internal function used to check if all the coordinates are the same.
#' @param data A list of datasets.
#' @param coords A vector of length 2 of the coordinate names.
#' @return A logical variable.

checkCoords <- function(data, coords) {
  
  coords_in <- sapply(data, function(dat) {
    if (inherits(dat,'data.frame'))
      if (!inherits(dat, 'sf')) coords %in% names(dat)
      else TRUE
    else if (inherits(dat, "Spatial")) {
      x_coord <- colnames(dat@coords)[1]
      y_coord <- colnames(dat@coords)[2]
      coords %in% c(x_coord, y_coord)
    }
  })
  if (!all(unlist(coords_in))) OK <- FALSE
  else OK <- TRUE
  
  OK
  
}

Try the PointedSDMs package in your browser

Any scripts or data that you put into this service are public.

PointedSDMs documentation built on Sept. 11, 2024, 7:06 p.m.