scales icon indicating copy to clipboard operation
scales copied to clipboard

Add palette capabilities: may_return_NA, accepts_native_output

Open zeehio opened this issue 3 years ago • 0 comments

This pull request (on top of #371) extends the definition of a palette by adding attributes to the palette function.

These attributes may be ignored if you don't care for them, but they can be used by the palette consumer (e.g. ggplot2) to be faster.

We define two new attributes on colour_ramp, gradient_n_pal, div_gradient_pal and seq_gradient_pal.

  • may_return_NA: If this attribute is set to FALSE, the palette consumer can safely assume that the palette won't return missing values (therefore skipping any check).
  • accepts_native_output: if this attribute is set to TRUE, the palette consumer can safely assume that the palette accepts an additional keyword argument named color_fmt which can take two values: "character" and "native". The palette consumer can call the palette with color_fmt = "native" to get colours in native format (as used in nativeRaster objects). The palette consumer can avoid the intermediate character representation of colours.

This is related to:

  • https://github.com/tidyverse/ggplot2/issues/4989

Proposed NEWS entry:

 * `colour_ramp`, `gradient_n_pal`, `div_gradient_pal` and `seq_gradient_pal` -based palettes 
   include additional attributes to let its user know that they are able to output colours in native
   format and whether or not they return missing values (#372, @zeehio)

zeehio avatar Nov 06 '22 14:11 zeehio