R/validation.R

Defines functions .validate_aoristic_inputs

.validate_aoristic_inputs <- function(data1, Xcoord, Ycoord, DateTimeFrom, DateTimeTo) {
  if (!is.data.frame(data1)) {
    stop("The input data specified is not a data.frame object", call. = FALSE)
  }

  requested <- list(
    Xcoord = Xcoord,
    Ycoord = Ycoord,
    DateTimeFrom = DateTimeFrom,
    DateTimeTo = DateTimeTo
  )
  for (argument in names(requested)) {
    column <- requested[[argument]]
    if (!is.character(column) || length(column) != 1L || is.na(column) || !nzchar(column)) {
      stop(sprintf("`%s` must name exactly one column in `data1`.", argument), call. = FALSE)
    }
    if (!column %in% names(data1)) {
      stop(sprintf("Column `%s` specified by `%s` was not found in `data1`.", column, argument),
           call. = FALSE)
    }
  }

  if (!inherits(data1[[DateTimeFrom]], "POSIXct")) {
    stop("The DateTimeFrom field is not a POSIXct object. Convert it before using this function.",
         call. = FALSE)
  }
  if (!inherits(data1[[DateTimeTo]], "POSIXct")) {
    stop("The DateTimeTo field is not a POSIXct object. Convert it before using this function.",
         call. = FALSE)
  }
  if (!is.numeric(data1[[Xcoord]])) {
    stop("The X coordinate field is not a numeric object. Change the variable format before continuing.",
         call. = FALSE)
  }
  if (!is.numeric(data1[[Ycoord]])) {
    stop("The Y coordinate field is not a numeric object. Change the variable format before continuing.",
         call. = FALSE)
  }

  invisible(TRUE)
}

Try the aoristic package in your browser

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

aoristic documentation built on Sept. 9, 2026, 9:08 a.m.