Check correct specification of colors
check_colors(x)
A vector of logical values, one for each specified color - TRUE
if
the color is specified correctly
This is a vectorized version of grDevices::col2rgb()
# simple case
mypal <- c("steelblue", "#FF1100")
check_colors(mypal)
#> steelblue #FF1100
#> TRUE TRUE
mypal2 <- rev(
scales::alpha(
colorRampPalette(RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50), 0.4
)
)
check_colors(mypal2)
#> #31369566 #35429B66 #394FA166 #3D5CA766 #4169AE66 #4576B466 #4F81BA66 #598DC066
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> #6298C666 #6CA3CC66 #76AED166 #81B7D666 #8CC0DB66 #97C9E066 #A3D2E566 #AEDAE966
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> #B9DFEC66 #C3E5F066 #CEEAF366 #D9EFF666 #E2F3F366 #E8F6E766 #EFF8DC66 #F5FBD066
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> #FBFDC466 #FEFBBA66 #FEF5B066 #FEEFA766 #FEE89D66 #FEE29366 #FDD98A66 #FDCF8066
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> #FDC57766 #FDBB6D66 #FDB16366 #FBA45C66 #F9975666 #F88A5066 #F67C4A66 #F46F4466
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> #EF633E66 #E9563866 #E34A3366 #DD3D2D66 #D7312766 #CD272666 #C31D2666 #B9132666
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> #AF092666 #A5002666
#> TRUE TRUE
# useful with long vectors to check at once if all cols are fine
all(check_colors(mypal2))
#> [1] TRUE