#' Define a goalie check classed return
#'
#' @export
#' @note Updated 2023-09-29.
#'
#' @param object `logical`.
#'
#' @param cause `character`.
#' Only applies when `object` vector contains any `FALSE` values.
#' The `cause` attribute must be named.
#' Cause values corresponding to `TRUE` must be set `NA`.
#'
#' @return
#' All `TRUE`: `logical`.
#' Any `FALSE`: `goalie`, which extends `logical`.
#'
#' @examples
#' ## Any FALSE.
#' x <- goalie(
#' object = c(FALSE, TRUE),
#' cause = c("xxx", NA_character_)
#' )
#' print(x)
#' print(cause(x))
#'
#' ## All TRUE.
#' x <- goalie(rep(TRUE, 2L))
#' print(x)
goalie <- function(object, cause) {
if (all(object)) {
if (identical(length(object), 0L)) {
stop("Invalid input.")
}
if (!is.null(names(object))) {
stop("Object is named.")
}
return(object)
}
new(Class = "goalie", ".Data" = object, "cause" = cause)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.