R/check_inputs.R

Defines functions check_gwrf_inputs

Documented in check_gwrf_inputs

#' Validate inputs for GWRF fitting
#'
#' @param formula A model formula.
#' @param data A data frame.
#' @param coords Numeric matrix or data frame with 2 columns.
#'
#' @return Invisibly TRUE if checks pass.
#' @keywords internal
check_gwrf_inputs <- function(formula, data, coords) {
  if (!inherits(formula, "formula")) {
    stop("formula must be a valid model formula.")
  }
  if (!is.data.frame(data)) {
    stop("data must be a data frame.")
  }

  coords <- as.matrix(coords)
  if (!is.numeric(coords) || ncol(coords) != 2) {
    stop("coords must be numeric with exactly 2 columns.")
  }
  if (nrow(coords) != nrow(data)) {
    stop("coords and data must have the same number of rows.")
  }

  mf <- model.frame(formula, data = data, na.action = stats::na.pass)
  if (nrow(mf) != nrow(data)) {
    stop("model.frame row count does not match data.")
  }

  response <- model.response(mf)
  if (!is.numeric(response)) {
    stop("Version 1 supports numeric regression responses only.")
  }

  invisible(TRUE)
}

Try the gwrf package in your browser

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

gwrf documentation built on Aug. 24, 2026, 5:15 p.m.