Skip to contents

Checks is the provided string contains valid color names or valid hex color values.

Usage

check_color(x, alt_null = FALSE, add_msg = NULL)

Arguments

x

Character. Color names and/or hex color values.

alt_null

Logical. Should argument accept NULL value.

add_msg

Is an additional message that can be printed over the standard function error message. You can:

  • pass the names of the arguments that failed the test by using {x_names} in the message body (e.g. "What are the {x_names}");

  • pass the names/hex values of the argument that failed the test by using {wrong_colors} in the message body (e.g. "{wrong_colors} are wrong")

Value

The function will throw an error if any element of the character vector is not a valid color name or a valid hex color value.

Examples


correct_color <- c("white")
wrong_color <- c("dick", "white")
wrong_colors <- c("dick", "white", "zombie")
wrong_hex <- "#hex"
correct_hex <- "#fffaaa"
null_hex <- NULL

if (FALSE) { # \dontrun{
check_color(wrong_color)
check_color(wrong_colors, add_msg = "Am I {wrong_colors}")
check_color(wrong_hex)
check_color(correct_color)
check_color(correct_hex)
check_color(null_hex, alt_null = TRUE)
check_color(null_hex, alt_null = FALSE)
} # }