Get a vector of colors whose names match a regular expression.
grepal
returns a vector of colors whose names match a regular expression (regex).
grepal(pattern, x = colors(), ignore_case = TRUE)
pattern |
A regular expression (specified as a string/character object). |
x |
A vector of R color names or a data frame of named colors
(i.e., whose names can be searched).
Default: |
ignore_case |
Should the case of pattern be ignored
(passed to |
By default, the base R vector of named colors (i.e., colors()
) is searched
for names matching a pattern
(which can be a simple string or regular expression).
If x
(i.e., the object to be searched) is provided,
it is must be a vector of color names or a data frame of named color objects
(e.g., a color palette).
The name grepal
is an abbreviation of grep
and "pal".
grepal("cyan") # With regular expressions: some_grey <- grepal("gr(a|e)y") start_grey <- grepal("^gr(a|e)y") only_grey <- grepal("^gr(a|e)y$") length(some_grey) length(only_grey) # With other color objects (df as x): grepal("blau", x = pal_unikn) grepal("SEE", x = pal_unikn_pref) # Applications: seecol(grepal("white"), col_bg = "lightblue2", title = "See 'white' colors()") olives <- grepal("olive") oranges <- grepal("orange") seecol(list(olives, oranges), pal_names = c("olives", "oranges"), title = "Comparing olives and oranges") seecol(grepal("SEE", pal_unikn), title = "All 'SEE' colors in pal_unikn") seecol(grepal("blau", pal_unikn_pref), title = "All 'blau' colors in pal_unikn_pref")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.