Remove alpha transparency from colors

unalpha(x, keepNA = FALSE, ...)

Arguments

x

character vector of R colors

keepNA

logical indicating whether NA values should be kept and therefore returned as NA. When keepNA=FALSE (default for backward compatibility) NA values are converted to "#FFFFFF" as done by grDevices::col2rgb().

...

additional arguments are ignored.

Value

character vector of R colors in hex format.

Details

This function simply removes the alpha transparency from R colors, returned in hex format, for example "#FF0000FF" becomes "#FF0000", or "blue" becomes "#0000FF".

It also silently converts R color names to hex format, where applicable.

Examples

unalpha(c("#FFFF00DD", "red", NA, "#0000FF", "transparent"))
#> [1] "#FFFF00" "#FF0000" "#FFFFFF" "#0000FF" "#FFFFFF"

unalpha(c("#FFFF00DD", "red", NA, "#0000FF", "transparent"), keepNA=TRUE)
#> [1] "#FFFF00" "#FF0000" NA        "#0000FF" "#FFFFFF"