R/flag_item.R

Defines functions flag_item.vctrs_vector flag_item.numeric flag_item.default flag_item

# The flagging function determines what things in the column should be flagged -
# colours inverted.
# This really only needed to be created for vctrs since not all of them support
# is.infinite() gracefully

flag_item <- function(item) UseMethod("flag_item")

#' @export
flag_item.default <- function(item) {

  if (length(item) > 1) stop("You gave me an item of length > 1 to flag")

  if (is.null(item)) return(TRUE)

  if (isTRUE(is.na(item))) return(TRUE)

  FALSE
}

#' @export
flag_item.numeric <- function(item) {

  if (length(item) > 1) stop("You gave me an item of length > 1 to flag")

  if (is.infinite(item)) return(TRUE)
  NextMethod()
}  

#' @export
flag_item.vctrs_vector <- function(item) {
  if (is_infinite_value_safely(item)) return(TRUE)
  NextMethod()
}
MilesMcBain/paint documentation built on Dec. 5, 2023, 9:11 a.m.