R/parse_hemisphere.R

Defines functions parse_hemisphere

Documented in parse_hemisphere

#' get hemisphere from long/lat coordinates
#'
#' BEWARE: EXPERIMENTAL
#'
#' @export
#' @param lon (character/numeric/integer) one or more longitude values
#' @param lat (character/numeric/integer) one or more latitude values
#' @details length(lon) == length(lat)
#' @return character vector of quadrants, one of: NE, NW, SE, SW.
#' if one of the coordinate values is invalid, and one is valid, you get
#' a length 1 string. if both coordinate values are bad, you get
#' a zero length string.
#'
#' Warnings are thrown on invalid values
#' @examples
#' # NE
#' parse_hemisphere("74.123E", "45N54.2356")
#' \dontrun{
#' # NW
#' parse_hemisphere(-120, 40.4183318)
#' # SW
#' parse_hemisphere(-120, -40.4183318)
#' # SE
#' parse_hemisphere(120, -40.4183318)
#'
#' # bad inputs, get one of the two strings
#' parse_hemisphere(-181, -40.4183318)
#' parse_hemisphere(-120, -192.4183318)
#'
#' # many inputs
#' library(randgeo)
#' pts <- rg_position(count = 1000)
#' lons <- as.character(vapply(pts, "[[", 1, 1))
#' lats <- as.character(vapply(pts, "[[", 1, 2))
#' parse_hemisphere(lons, lats)
#' }
parse_hemisphere <- function(lon, lat) {
  lint_inputs(lon, lat, "")
  stopifnot(length(lon) == length(lat))
  pz_hemisphere(lon, lat)
}

Try the parzer package in your browser

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

parzer documentation built on Dec. 20, 2021, 5:08 p.m.