R/vld.R

Defines functions vld_colour vld_color

Documented in vld_color vld_colour

#' Validate Color String
#'
#' Validates whether x is a string (non-missing character vector of length 1)
#' that specifies a color.
#'
#' @inheritParams chk::chk_true
#' @return A flag indicating whether the object was validated.
#' @seealso [chk_color()]
#' @name vld_color
NULL

#' @describeIn vld_color Validate Color String
#'
#' @export
#'
#' @examples
#'
#' # vld_color
#' vld_color("blue")
#' vld_color("glue")
vld_color <- function(x) {
  vld_string(x) && !inherits(try(grDevices::col2rgb(x), silent = TRUE), "try-error")
}

#' @describeIn vld_color Validate Colour String
#'
#' @export
#'
#' @examples
#'
#' # vld_color
#' vld_colour("blue")
#' vld_colour("glue")
vld_colour <- function(x) {
  vld_color(x)
}

Try the tinter package in your browser

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

tinter documentation built on April 19, 2020, 4:15 p.m.