R/isColourStr.R

Defines functions isColourStr

Documented in isColourStr

#' Test if \code{R} can interpret a string as a colour
#'
#' Test if \code{R} can interpret a string as a colour
#'
#' @param col The string to be tested.
#' @return A boolean value, \code{TRUE} if col is a valid colour, \code{FALSE} otherwise
#' @export
#' @examples
#' isColourStr('black')
#' isColourStr('blakc')
#'
isColourStr <- function(col) {
    if(base::missing(col)) col

    sapply(col,
        function(X) {
            tryCatch(is.matrix(grDevices::col2rgb(X)),
                error = function(e) FALSE)
        }
    )
}

Try the crestr package in your browser

Any scripts or data that you put into this service are public.

crestr documentation built on Jan. 6, 2023, 5:23 p.m.