Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
56 lines (51 sloc)
1.24 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Pipe operator | |
#' | |
#' See \code{magrittr::\link[magrittr]{\%>\%}} for details. | |
#' | |
#' @name %>% | |
#' @rdname pipe | |
#' @keywords internal | |
#' @export | |
#' @importFrom magrittr %>% | |
#' @usage lhs \%>\% rhs | |
NULL | |
# Grab the color opening and closing tags for a given color | |
get_open_close <- function(c) { | |
if (c == "white") { | |
num_colors <- 1 | |
} else { | |
num_colors <- 256 | |
} | |
if (crayon:::is_r_color(c)) { | |
o_c <- crayon:::style_from_r_color(c, | |
bg = FALSE, num_colors = num_colors, grey = FALSE | |
) | |
} else { | |
stop("Don't know how to handle non-R color.") | |
} | |
out <- tibble::as_tibble(o_c) | |
return(o_c) | |
} | |
#' Insert Rainbow | |
#' | |
#' Take the string "rainbow" and replace it with c("red", "orange", "yellow", "green", "blue", "purple") | |
#' | |
#' @param clr (character) A vector of one or more colors. | |
#' | |
#' @return A character vector of color names. | |
#' @export | |
#' | |
#' @examples | |
#' | |
#' insert_rainbow("rainbow") | |
#' insert_rainbow(c("lightsteelblue", "rainbow", "lightsalmon")) | |
insert_rainbow <- function(clr) { | |
if (inherits(clr, "crayon")) { | |
return(clr) | |
} else if (any(clr == "rainbow")) { | |
rb_idx <- which(clr == "rainbow") | |
clr[rb_idx] <- list(c("red", "orange", "yellow", "green", "blue", "purple")) | |
clr <- unlist(clr) | |
} | |
return(clr) | |
} |