rcols_as_hex: Convert R's built-in named colours to hex codes

View source: R/plot_tools.R

rcols_as_hexR Documentation

Convert R's built-in named colours to hex codes

Description

Convert R's built-in named colours to hex codes

Usage

rcols_as_hex(vec = NULL, distinct = FALSE)

Arguments

vec

(Character) A character vector of R's built-in named colours. If left NULL, the entire contents of grDevices::colours() will be used.

distinct

(Logical) Should only distinct colours be returned? Distinct colours do not share the same (0:255)^3 RGB space, and do not have the same hex code. Defaults to FALSE so that you don't get unexpectedly-short vectors.

Value

A named character vector of hex colours that were converted from R's built-in names. The names are the original R colour names that were provided in vec.

Authors

Examples

rcols_as_hex(c("tomato", "steelblue"))
#>    tomato steelblue
#> "#FF6347" "#4682B4"

rcols_as_hex()
#>     white    aliceblue    antiquewhite    ... for all colours in colours()
#> "#FFFFFF"    "#F0F8FF"    "#FAEBD7"       ... for all colours in colours()

rcols_as_hex(distinct = TRUE)
#>     white    aliceblue    antiquewhite    ... for all in colours(distinct = TRUE)
#> "#FFFFFF"    "#F0F8FF"    "#FAEBD7"       ... for all in colours(distinct = TRUE)

rcols_as_hex(c("snow", "snow1"))
#>      snow     snow1
#> "#FFFAFA" "#FFFAFA"

rcols_as_hex(c("snow", "snow1"), distinct = TRUE)
#>      snow
#> "#FFFAFA"


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.