scales
scales copied to clipboard
Add palette capabilities: may_return_NA, accepts_native_output
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 toFALSE, 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 toTRUE, the palette consumer can safely assume that the palette accepts an additional keyword argument namedcolor_fmtwhich can take two values:"character"and"native". The palette consumer can call the palette withcolor_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)