valid_hex: Test whether a string is a valid hexadecimal color value

Description Usage Arguments Details Value Examples

View source: R/valid_hex.R

Description

Test whether a string is a valid hexadecimal color value

Usage

1
valid_hex(hex, hash = TRUE)

Arguments

hex

character vector containing string(s) to test as hex value(s).

hash

boolean, default TRUE; indicates whether valid_hex() should verify whether hex codes begin with the hash symbol (#). If FALSE, hex codes are considered valid whether or not they begin with the hash symbol. Defaults to true because internal print functions require hashed hex codes. This option is provided in case this function can serve other uses, e.g. checking if a character vector contains any valid hex strings (with or without the hex symbol).

Details

A hex code is valid if:

Three-character hex codes are interpolated to six-character codes by repeating each element twice. Eight- character hex codes contain two digits (either prepended or appended) representing transparency (alpha).

Value

vector of boolean values indicating whether string(s) are valid hex code.

Examples

1
2
valid_hex("#ffffff")
valid_hex("123456", hash = FALSE)

simmwill/coolors documentation built on Dec. 23, 2021, 2:23 a.m.