Colour space conversion

This is the raison d’être of the package. Take a matrix or data frame with colour channels in the columns, and convert it from one colour space to another. Channels are automatically capped if they have defined bounds, and any NaN, NA, Inf, or -Inf values in the input will result in a row of NA values in the output.


Convert between colour spaces

Colour comparison

Getting a numeric value describing the distance between two colours is not a trivial task, and several metrics have been devised for that. farver supports a range of these, and allows you to compare colours in any space with each others.


Calculate the distance between colours

Converting to and from colour strings

The native format of colours in R (and other languages) is often hexadecimal encoded rgb values (#RRGGBB). farver provides utilities for easily going back and forth between this and any colour space.


Encode colours into RGB hex-strings


Decode RGB hex-strings into colour values

Colour string manipulation

As colours are often encoded as strings, manipulation of individual channels requires decoding. and then encoding. farver does away with that by providing a range of functions for directly manipulating channels in colour strings.

set_channel() add_to_channel() multiply_channel() raise_channel() cap_channel() get_channel()

Modify colour space channels in hex-encoded colour strings

Converting to and from native colour representation

Under the hood, R encodes colours as integers, with the 32 bit in the integer divided beetween red, green, blue, and alpha, giving them 8 bit (or 256 values) each. farver provides a simple and fast way of converting between the native integer representation and the string representation.

encode_native() decode_native()

Convert to and from the R native colour representation