Skip to content

Option for encode_colour() to preserve input alpha channel #56

Description

@dmuenz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions