Skip to content

Commit

Permalink
Relax the requirements on color inputs (for a CRAN reverse dependency…
Browse files Browse the repository at this point in the history
… check). c8f6b4a
  • Loading branch information
haozhu233 committed Jan 23, 2024
1 parent aeb36f5 commit 8b76cca
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions R/spec_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ spec_color <- function(x, alpha = 1, begin = 0, end = 1,
html_color_ <- function(color) {
# HTML colors are a subset of R colors, not including
# numbered versions like darkgoldenrod2 (issue #726)
if (substr(color, 1, 1) != "#" &&
!grepl("[[:digit:]]", color) )
return(color)

rgba_code <- col2rgb(color, alpha = TRUE)
rgba_code[4] <- round(rgba_code[4])
return(paste0("rgba(", paste(rgba_code, collapse = ", "), ")"))
# 2024-01-23 Hao: Move it to a try catch flavor.
tryCatch(
{rgba_code <- col2rgb(color, alpha = TRUE)},
error = function(e) {return(color)},
warning = function(w) {return(color)},
finally = function(f) {
rgba_code[4] <- round(rgba_code[4])
return(paste0("rgba(", paste(rgba_code, collapse = ", "), ")"))
}
)
}

html_color <- function(colors) {
Expand Down

0 comments on commit 8b76cca

Please sign in to comment.