😎 Give your xaringan slides some style
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
976B

  1. prepare_colors <- function(colors = NULL) {
  2. if (is.null(colors) || length(colors) < 1) return(NULL)
  3. if (is.null(names(colors))) {
  4. stop(
  5. "`colors` must have names corresponding to valid CSS classes",
  6. call. = FALSE
  7. )
  8. }
  9. if (any(grepl("\\s", names(colors)))) {
  10. stop(
  11. "Color names in `colors` must be valid CSS classes",
  12. " and cannot contain spaces",
  13. call. = FALSE)
  14. }
  15. if (any(grepl("[^[:alpha:]_-]", names(colors)))) {
  16. stop("Color names in `colors` must be valid CSS classes", call. = FALSE)
  17. }
  18. whisker::iteratelist(colors, "color_name")
  19. }
  20. full_length_hex <- function(x) {
  21. if (!grepl("^#", x)) {
  22. stop(paste0('"', x, '" is not a hexadecimal color'))
  23. }
  24. x <- sub("^#", "", x)
  25. if (nchar(x) == 3) {
  26. x <- strsplit(x, character(0))[[1]]
  27. x <- rep(x, each = 2)
  28. x <- paste(x, collapse = "")
  29. } else if (nchar(x) != 6) {
  30. stop(paste0('"', x, '" is not a hexadecimal color'))
  31. }
  32. paste0("#", x)
  33. }