diff --git a/DESCRIPTION b/DESCRIPTION index 4e0f5b9..9832373 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,7 +39,6 @@ Suggests: curl, jsonlite, knitr, - multicolor, rmarkdown, testthat RoxygenNote: 7.2.3 diff --git a/R/say.r b/R/say.r index 344f80e..94d47d8 100644 --- a/R/say.r +++ b/R/say.r @@ -77,21 +77,6 @@ #' say() #' say("what") #' say('time') -#' -#' if (requireNamespace("multicolor", quietly=TRUE) && -#' requireNamespace("jsonlite", quietly=TRUE)) { -#' say("meow", "cat", what_color = "blue") -#' say('time', "poop", by_color = "cyan", what_color = "pink") -#' -#' library(jsonlite) -#' say("hello world", -#' by = "hypnotoad", -#' what_color = c("royalblue1", "tomato2"), -#' by_color = c("rainbow", "rainbow")) -#' say("whats up", -#' what_color = crayon::cyan$bgMagenta, -#' by_color = c("salmon1", "springgreen")) -#' } #' #' say("who you callin chicken", "chicken") #' say("ain't that some shit", "poop") @@ -219,8 +204,9 @@ say <- function(what="Hello world!", by="cat", c <- crayon::make_style(c) out <- c(txt) } else if (length(c) >= 1) { - out <- multicolor::multi_color(txt, c, - type = "string") + stop("this functionality requires multicolor, which is temporarily not on CRAN") + # out <- multicolor::multi_color(txt, c, + # type = "string") } } return(out) diff --git a/R/utils.R b/R/utils.R index 509a2cd..07610d9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -6,10 +6,11 @@ check_color <- function(clr) { if (all(inherits(clr, "character"))) { if (length(clr) > 1 || clr == "rainbow") { - check4pkg("multicolor") + # check4pkg("multicolor") # Change "rainbow" into roygbiv - clr <- multicolor::insert_rainbow(clr) + # clr <- multicolor::insert_rainbow(clr) + clr <- cowsay_insert_rainbow(clr) if (!all(is.character(clr))) { stop("If color arguments have > length 1, all colors must be of class character", @@ -19,3 +20,16 @@ check_color <- function(clr) { } return(clr) } + +cowsay_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) +} diff --git a/man/say.Rd b/man/say.Rd index 8a3f7e2..63364ae 100644 --- a/man/say.Rd +++ b/man/say.Rd @@ -107,21 +107,6 @@ say() say("what") say('time') -if (requireNamespace("multicolor", quietly=TRUE) && -requireNamespace("jsonlite", quietly=TRUE)) { -say("meow", "cat", what_color = "blue") -say('time', "poop", by_color = "cyan", what_color = "pink") - -library(jsonlite) -say("hello world", - by = "hypnotoad", - what_color = c("royalblue1", "tomato2"), - by_color = c("rainbow", "rainbow")) -say("whats up", - what_color = crayon::cyan$bgMagenta, - by_color = c("salmon1", "springgreen")) -} - say("who you callin chicken", "chicken") say("ain't that some shit", "poop") say("icanhazpdf?", "cat") diff --git a/tests/testthat/test-say.R b/tests/testthat/test-say.R index f4ac840..cbf35f6 100644 --- a/tests/testthat/test-say.R +++ b/tests/testthat/test-say.R @@ -12,7 +12,7 @@ test_that("say types works as expected", { }) test_that("say works with multicolor", { - skip_if_not_installed("multicolor") + # skip_if_not_installed("multicolor") expect_equal( length(suppressMessages(say("foo", by_color = "cyan"))) + 1, @@ -26,30 +26,33 @@ test_that("say works with multicolor", { say(what = "rms", by = "rms", type = "print") ) - expect_equal( - say(what = "I'm a rare Irish buffalo", - by = "buffalo", - what_color = "pink", - by_color = c("green", "white", "orange")), - say(what = "I'm a rare Irish buffalo", - by = "buffalo", - type = "print") - ) + # TODO: undo comments when multicolor comes back + # expect_equal( + # say(what = "I'm a rare Irish buffalo", + # by = "buffalo", + # what_color = "pink", + # by_color = c("green", "white", "orange")), + # say(what = "I'm a rare Irish buffalo", + # by = "buffalo", + # type = "print") + # ) - expect_equal( - say("I'm not dying, you're dying", "yoda", - what_color = "green", - by_color = colors()), - say("I'm not dying, you're dying", "yoda", - type = "print") - ) + # TODO: undo comments when multicolor comes back + # expect_equal( + # say("I'm not dying, you're dying", "yoda", + # what_color = "green", + # by_color = colors()), + # say("I'm not dying, you're dying", "yoda", + # type = "print") + # ) - expect_equal( - say("asdfghjkl;'", "chicken", - what_color = blue, - by_color = c("rainbow", colors()[sample(100, 1)], "rainbow")), - say("asdfghjkl;'", "chicken", type = "print") - ) + # TODO: undo comments when multicolor comes back + # expect_equal( + # say("asdfghjkl;'", "chicken", + # what_color = blue, + # by_color = c("rainbow", colors()[sample(100, 1)], "rainbow")), + # say("asdfghjkl;'", "chicken", type = "print") + # ) skip_if(!crayon::has_color(), message = "Shouldn't fail if colors can't be applied.") expect_error( diff --git a/vignettes/cowsay.Rmd b/vignettes/cowsay.Rmd index 8497289..015082d 100644 --- a/vignettes/cowsay.Rmd +++ b/vignettes/cowsay.Rmd @@ -14,7 +14,7 @@ vignette: > --- ```{r echo=FALSE} -has_multicolor <- requireNamespace("multicolor", quietly = TRUE) +# has_multicolor <- requireNamespace("multicolor", quietly = TRUE) knitr::opts_chunk$set( comment = "#>", collapse = TRUE @@ -104,68 +104,3 @@ String say("hello world", by = "cow", type = "string") ``` - -## Add color - -```{r eval = has_multicolor} -library(jsonlite) -library(multicolor) -``` - - -We rely on the [`crayon`](https://github.com/r-lib/crayon) package for color and the [`multicolor`](https://github.com/aedobbyn/multicolor) package for multiple colors. The arguments you supply to `what_color` and `by_color` can be strings -- either the color name or a hex value -- or a [function of class `crayon`](https://github.com/r-lib/crayon#styles). - - -```{r eval = has_multicolor} -say(what = "fortune", - by = "rabbit", - what_color = "#FF4500", - by_color = "red") -``` - - -`colors()` are all supported as are any `rgb` values that evaluate to a string. Supplying multiple colors for `what_color` or `by_color` is allowed, as long as they're in a character vector. "rainbow" is also allowed. - -```{r eval = has_multicolor} -# make a vector of animals safe to use on windows in case vignette built on windows -not_on_windows <- c('shortcat','longcat','fish','signbunny','stretchycat', - 'anxiouscat','longtailcat','grumpycat','mushroom') -names_safe <- names(animals)[!names(animals) %in% not_on_windows] -``` - -```{r eval = has_multicolor} -say(what = "fortune", - by = sample(names_safe, 1), - what_color = rgb(.1, .2, .3), - by_color = sample(colors(), 5), - type = "message") -``` - - -```{r eval = has_multicolor} -say(what = "fortune", - by = sample(names_safe, 1), - what_color = rgb(.1, .2, .3), - by_color = sample(colors(), 5), - type = "message") -``` - -`"rainbow"` is the same as `c("red", "orange", "yellow", "green", "blue", "purple")`. Saves you a bit of typing. - -```{r eval = has_multicolor} -say(what = "foobar", - by = "shark", - what_color = "rainbow", - by_color = c("rainbow", "rainbow", "rainbow")) -``` - -The main advantage of using `crayon` functions instead of color strings is the ability to combine styles together. - -```{r eval = has_multicolor} -library(crayon) - -say(what = "fortune", - by = "egret", - what_color = bgBlue$white$italic, - by_color = bold$green) -```