@@ -69,20 +69,34 @@ check_pal <- function(arg) {
6969# '
7070# ' @param arg argument passed as colour
7171# ' @returns none
72+ # ' @importFrom grDevices colors
7273# ' @keywords internal
7374check_colour <- function (arg ) {
74- # colour should be character, one of the following:
75- # "rl_green", "rl_red", "rl_blue", "rl_purple", "rl_orange", "rl_magenta", or
76- # a hex colour
77- # first test if it is a character vector of length 1
78- if (length(arg ) > 1 ) {
79- stop(" 'colour' must be a hex colour or one of rl_green, rl_red, rl_blue,
80- rl_purple, rl_orange, or rl_magenta" , call. = FALSE )
81- } else if (! arg %in% c(" rl_green" , " rl_red" , " rl_blue" , " rl_purple" ,
82- " rl_orange" , " rl_magenta" )) {
83- if (! grepl(" ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$" , arg )) {
84- stop(" 'colour' must be a hex colour or one of rl_green, rl_red, rl_blue,
85- rl_purple, rl_orange, or rl_magenta" , call. = FALSE )
75+ # colour should be character vector, each element one of the following:
76+ # "rl_green", "rl_red", "rl_blue", "rl_yellow", "rl_purple", "rl_orange",
77+ # "rl_magenta", or a hex colour
78+
79+ # Check if arg is a character vector
80+ if (! is.character(arg )) {
81+ stop(" 'colour' must be a character vector" , call. = FALSE )
82+ }
83+
84+ # Define valid named colours
85+ valid_colours <- c(colors(), " rl_green" , " rl_red" , " rl_blue" , " rl_yellow" ,
86+ " rl_purple" , " rl_orange" , " rl_magenta" )
87+
88+ # Check each element in the vector
89+ for (i in seq_along(arg )) {
90+ colour <- arg [i ]
91+
92+ # Check if it's a valid named colour
93+ if (! colour %in% valid_colours ) {
94+ # If not a named colour, check if it's a valid hex colour
95+ if (! grepl(" ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$" , colour )) {
96+ stop(" 'colour[" , i , " ]' must be a hex colour, a named colour or one of
97+ rl_green, rl_red, rl_blue, rl_yellow, rl_purple, rl_orange,
98+ or rl_magenta" , call. = FALSE )
99+ }
86100 }
87101 }
88102}
0 commit comments