Skip to contents

Convert r,g,b,a values as string or numeric to hex

Usage

rgb2hex(red, green, blue, alpha = FALSE)

Arguments

red

chr/num Either a CSS rgb() or rgba() declaration as a string, or the red value as numeric.

alpha

lgl/num Whether to include the alpha value (an 8 digit hex) in the output or not, or the alpha value to apply, If set to TRUE, and alpha is not set, an alpha value of 1 will be appended. If numeric, a value between 0 & 1 inclusive to set as the alpha value.

Value

chr The hex value

Examples

rgb2hex("rgba(18,180,211,1)", alpha = TRUE)
#> [1] "#12B4D3FF"
rgb2hex("rgba(18,180,211,1)", alpha = FALSE)
#> [1] "#12B4D3"