I have a vector v whose elements can be any valid R color string, i.e. color names or hex strings. I want to use decode_colour() and encode_colour() to standardize all the color strings as hex strings. Using decode_colour(m, alpha = TRUE) works as expected, but my issue is with encode_colour() -- I can't get it to preserve the alpha channel from the input colors.
encode_colour() has an alpha parameter, but it seems it can only be used to overwrite the input alpha level. I tried using alpha = TRUE, but it seems this is actually equivalent to alpha = 1, meaning force the alpha level of all input colors to be 1. Could this behavior be changed so that alpha = TRUE preserves the input alpha channel?
library(farver)
v <- c("red", "#FF000080", "transparent")
decode_colour(v, alpha = TRUE) |> encode_colour()
#> [1] "#FF0000" "#FF0000" "#FFFFFF"
# I'd like to be able to write something like the following to preserve the original alpha levels in `v`
decode_colour(v, alpha = TRUE) |> encode_colour(alpha = TRUE)
Thanks for your consideration.
I have a vector
vwhose elements can be any valid R color string, i.e. color names or hex strings. I want to usedecode_colour()andencode_colour()to standardize all the color strings as hex strings. Usingdecode_colour(m, alpha = TRUE)works as expected, but my issue is withencode_colour()-- I can't get it to preserve the alpha channel from the input colors.encode_colour()has analphaparameter, but it seems it can only be used to overwrite the input alpha level. I tried usingalpha = TRUE, but it seems this is actually equivalent toalpha = 1, meaning force the alpha level of all input colors to be 1. Could this behavior be changed so thatalpha = TRUEpreserves the input alpha channel?Thanks for your consideration.