R: Modify colour space channels in hex-encoded colour strings

manip_channel {farver} | R Documentation

## Modify colour space channels in hex-encoded colour strings

### Description

This set of functions allows you to modify colours as given by strings, whithout first decoding them. For large vectors of colour values this should provide a considerable speedup.

### Usage

    set_channel(
      colour,
      channel,
      value,
      space = "rgb",
      white = "D65",
      na_value = NA
    )

    add_to_channel(
      colour,
      channel,
      value,
      space = "rgb",
      white = "D65",
      na_value = NA
    )

    multiply_channel(
      colour,
      channel,
      value,
      space = "rgb",
      white = "D65",
      na_value = NA
    )

    raise_channel(
      colour,
      channel,
      value,
      space = "rgb",
      white = "D65",
      na_value = NA
    )

    cap_channel(
      colour,
      channel,
      value,
      space = "rgb",
      white = "D65",
      na_value = NA
    )

    get_channel(colour, channel, space = "rgb", white = "D65", na_value = NA)

### Arguments

`colour` | A character string giving colours, either as hexadecimal strings or accepted colour names.
`channel` | The channel to modify or extract as a single letter, or `'alpha'` for the alpha channel.
`value` | The value to modify with
`space` | The colour space the channel pertains to. Allowed values are: `"cmy"`, `"cmyk"`, `"hsl"`, `"hsb"`, `"hsv"`, `"lab"` (CIE L*ab), `"hunterlab"` (Hunter Lab), `"oklab"` , `"lch"` (CIE Lch(ab) / polarLAB), `"luv"`, `"rgb"` (sRGB), `"xyz"`, `"yxy"` (CIE xyY), `"hcl"` (CIE Lch(uv) / polarLuv), or `"oklch"` (Polar form of oklab)
`white` | The white reference of the channel colour space. Will only have an effect for relative colour spaces such as Lab and luv. Any value accepted by `as_white_ref()` allowed.
`na_value` | A valid colour string or `NA` to use when `colour` contains `NA` elements. The general approach in farver is to carry `NA` values over, but if you want to mimick `col2rgb()` you should set `na_value = 'transparent'`, i.e. treat `NA` as transparent white.

### Value

A character vector of the same length as `colour` (or a numeric vector in the case of `get_channel()`)

### See Also

Other encoding and decoding functions: `decode_colour()`, `encode_colour()`

### Examples

    spectrum <- rainbow(10)

    # set a specific channel
    set_channel(spectrum, 'r', c(10, 50))
    set_channel(spectrum, 'l', 50, space = 'lab')
    set_channel(spectrum, 'alpha', c(0.5, 1))

    # Add value to channel
    add_to_channel(spectrum, 'r', c(10, 50))
    add_to_channel(spectrum, 'l', 50, space = 'lab')

    # Multiply a channel
    multiply_channel(spectrum, 'r', c(10, 50))
    multiply_channel(spectrum, 'l', 50, space = 'lab')

    # set a lower bound on a channel
    raise_channel(spectrum, 'r', c(10, 50))
    raise_channel(spectrum, 'l', 20, space = 'lab')

    # set an upper bound on a channel
    cap_channel(spectrum, 'r', c(100, 50))
    cap_channel(spectrum, 'l', 20, space = 'lab')

[Package farver version 2.1.0 Index]