Learn R Programming

evanverse (version 0.4.0)

hex2rgb: Convert HEX color(s) to RGB numeric components

Description

Convert a single HEX color string or a character vector of HEX strings to RGB numeric components. The function accepts values with or without a leading #. Messaging uses cli if available and falls back to message().

Usage

hex2rgb(hex)

Value

If hex has length 1, a named numeric vector with elements c(r, g, b). If hex has length > 1, a named list where each element is a named numeric vector for the corresponding input.

Arguments

hex

Character. A HEX color string (e.g. "#FF8000") or a character vector of HEX codes. No NA values allowed.

Examples

Run this code
hex2rgb("#FF8000")
hex2rgb(c("#FF8000", "#00FF00"))

Run the code above in your browser using DataLab