Add Multiple Colors to your Console Output

Add multiple colors to text that is printed to the console.

Travis buildstatus AppVeyor buildstatus Coveragestatus CRAN_Status_Badge rstudio mirrordownloads

Apply multiple colors to your messages, warnings, and errors. Built on the crayon package. Pairs nicely with cowsay. The blog post has a bit of backstory and walkthrough of how it works.


Stable, from CRAN (does not include crawl):


or the development version from GitHub:


Note: colors cannot be applied in the R GUI and certain other environments. RStudio or any terminal should work fine1.



Supply a character vector of colors to colors. This defaults to "rainbow", i.e., c("red", "orange", "yellow", "green", "blue", "purple").

multi_color("Hello world")


If you want to unveil your creation slowly (as @cortinah’s whale gif above), use crawl. You can vary the speed with the pause argument.


The text supplied will be divided into even(ish) chunks of those colors when recycle_chars is false. If it’s true, each color will apply to a single character, and the colors vector will be recycled over the lenght of the input string supplied.

Any character vector of R colors or hex values are fair game.


The default direction is vertical, but horizontal is also an option by setting the direction param to “horizontal”.

The default type messages the result. If you want the bare string back with color encodings attached, use type = "string", which looks like:

multi_color("Why are avocado pits so big?",
  type = "string")


So you can ask important questions ☝️and answer them colorfully 👇:

multi_color("The wild avocado grows in subtropical jungles, so the new sprout has to get several feet tall before it can share sunlight (to make food) with its neighbors. Until it grows out of their shadows, it relies on nutrients in the seed, so it'd better be big.",
                   sample(10, 1)))


ASCII art with cowsay

All cowsay animals are exported in multicolor::things, but to get the animals to speak, you need cowsay.

say(what = "holygrail", 
    by = "yoda",
    what_color = "olivedrab",
    by_color = colors()[which(grepl("green", colors()))])


Error in style:

my_error <- multi_color("An unknown error has occurred.", 
                        type = "string")


And with character:

my_msg <- 
  say(what = "Error: something went horribly wrong",
    by = "rms",
    what_color = viridisLite::magma(5)[3],
    by_color = viridisLite::magma(10),
    type = "string")
e <- simpleError(my_msg)
tryCatch(log("foo"), error = function(e) message(my_msg))


Or just send messages to your users that they’ll want to read.

this_variable <- "foo"
this_option <- "bar"
say(what = 
      glue::glue("Aha, I see you set {this_variable} to {this_option}. Excellent choice."),
    by = "owl",
    what_color = c("seagreen3", "turquoise3", "seagreen3"),
    by_color = c("turquoise3", "seagreen3", "turquoise3"))


That’s it! PRs & bug reports v welcome. 🎨

1 If coloring isn’t possible, you’ll get a warning on load and every time multi_color evaluates. The type argument will auto-set to "string". To check how these environments are determined, see multicolor:::use_color. If using multicolor in another package, you might consider inserting a replacement for the case when this evaluates to FALSE.


multicolor 0.1.1

  • crawl() allows for applying multi_color with pauses in between characters or lines
    • Added @cortinah as package author
  • The recycle_chars parameter allows for the option of applying each color to a single character or to an equal-sized portion of the input txt

multicolor 0.1.0

  • First version of multicolor!

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1.2 by Amanda Dobbyn, 7 days ago

Report a bug at

Browse source code at

Authors: Amanda Dobbyn [aut, cre] , Hernando Cortina [aut]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports cowsay, crayon, dplyr, glue, magrittr, purrr, stringi, stringr, tibble, tidyr

Suggests covr, fansi, knitr, rmarkdown, testthat, viridisLite, wesanderson

Suggested by cowsay.

See at CRAN