R/fails.R

Defines functions failTF failState failProofed failYear

Documented in failProofed failState failTF failYear

#' Fail if incorrect year supplied
#'
#' Internal function that fails if an incorrect year is provided.
#'
#' @importFrom assertthat assert_that
#' @importFrom rlang is_integerish
#'
#' @param year The year in which the Harvest Information Program data were
#'   collected
#'
#' @author Abby Walter, \email{abby_walter@@fws.gov}
#' @references \url{https://github.com/USFWS/migbirdHIP}

failYear <-
  function(year) {
    assertthat::assert_that(
      is_integerish(year),
      year >= 2020,
      year <= REF_CURRENT_SEASON,
      msg =
        paste0(
          "`year` must be a whole number between 2020 and ",
          REF_CURRENT_SEASON,
          "."
        )
    )
  }

#' Fail if non-proofed data frame supplied
#'
#' Internal function that fails if a tibble without \code{errors} field
#' (generated by \code{\link{proof}}) is provided.
#'
#' @importFrom assertthat assert_that
#'
#' @param proofed_data The object created after error flagging data with
#'   \code{\link{proof}}
#'
#' @author Abby Walter, \email{abby_walter@@fws.gov}
#' @references \url{https://github.com/USFWS/migbirdHIP}

failProofed <-
  function(proofed_data) {
    assert_that(
      "errors" %in% names(proofed_data), msg = "`errors` field not in data.")
  }

#' Fail if bad state abbreviation supplied
#'
#' Internal function that fails if a bad state abbreviation is provided.
#'
#' @importFrom assertthat assert_that
#'
#' @param state Any abbreviation for one of the 49 contiguous states:
#' \itemize{
#' \item `r REF_ABBR_49_STATES`}
#'
#' @author Abby Walter, \email{abby_walter@@fws.gov}
#' @references \url{https://github.com/USFWS/migbirdHIP}

failState <-
  function(state) {
    assert_that(
      state %in% REF_ABBR_49_STATES,
      msg =
        paste0(
          "`state` one of acceptable state abbreviations: ",
          REF_ABBR_49_STATES, ".")
    )
  }

#' Fail if TRUE or FALSE is not supplied
#'
#' Internal function that fails if something other than TRUE or FALSE is
#' supplied.
#'
#' @importFrom assertthat assert_that
#'
#' @param TF Must be TRUE, FALSE, T, or F
#'
#' @author Abby Walter, \email{abby_walter@@fws.gov}
#' @references \url{https://github.com/USFWS/migbirdHIP}

failTF <-
  function(TF) {
    assert_that(
      TF %in% c(TRUE, FALSE, T, F),
      msg = "param not TRUE, FALSE, T, or F.")
  }
USFWS/migbirdHarvestData documentation built on July 16, 2025, 10:10 p.m.