Colored Terminal Output

Colored terminal output on terminals that support 'ANSI' color and highlight codes. It also works in 'Emacs' 'ESS'. 'ANSI' color support is automatically detected. Colors and highlighting can be combined and nested. New styles can also be created easily. This package was inspired by the 'chalk' 'JavaScript' project.


Project Status: Active - The project has reached a stable, usable state and is being actively developed. Linux Build Status Windows Build status CRAN RStudio mirror downloads Coverage Status

With crayon it is easy to add color to terminal output, create styles for notes, warnings, errors; and combine styles.

ANSI color support is automatically detected and used. Crayon was largely inspired by chalk.



Crayon defines several styles, that can be combined. Each style in the list has a corresponding function with the same name.

General styles

  • reset
  • bold
  • blurred (usually called dim, renamed to avoid name clash)
  • italic (not widely supported)
  • underline
  • inverse
  • hidden
  • strikethrough (not widely supported)

Text colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • silver (usually called gray, renamed to avoid name clash)

Background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite

Screenshot on OSX


The styling functions take any number of character vectors as arguments, and they concatenate and style them:

cat(blue("Hello", "world!\n"))

Crayon defines the %+% string concatenation operator, to make it easy to assemble stings with different styles.

cat("... to highlight the " %+% red("search term") %+% " in a block of text\n")

Styles can be combined using the $ operator:

cat(yellow$bgMagenta$bold('Hello world!\n'))

Styles can also be nested, and then inner style takes precedence:

  'I am a green line ' %+%
  blue$underline$bold('with a blue substring') %+%
  ' that becomes green again!\n'

It is easy to define your own themes:

error <- red $ bold
warn <- magenta $ underline
note <- cyan
cat(error("Error: subscript out of bounds!\n"))
cat(warn("Warning: shorter argument was recycled.\n"))
cat(note("Note: no such directory.\n"))

256 colors

Most modern terminals support the ANSI standard for 256 colors, and you can define new styles that make use of them. The make_style function defines a new style. It can handle R's built in color names (see the output of colors()), and also RGB specifications, via the rgb() function. It automatically chooses the ANSI colors that are closest to the specified R and RGB colors, and it also has a fallback to terminals with 8 ANSI colors only.

ivory <- make_style("ivory")
bgMaroon <- make_style("maroon", bg = TRUE)
fancy <- combine_styles(ivory, bgMaroon)
cat(fancy("This will have some fancy colors"), "\n")


MIT @ Gábor Csárdi



  • Style fucntions convert arguments to character now

  • Autodetect RStudio ANSI support

  • col_align() gains type argument, default "width" (#54).


  • Removed dependency to memoise (@brodieG, #25)

  • Fixed a test case that changed the crayon.enabled setting, potentially (@brodieG)

  • Added crayon.colors option, to specify the number of colors explicitly

  • TERM=xterm and tput colors=8 will use 256 colors, as 256 colors are usually supported in this case (#17)

  • Support colors in ConEmu and cmder, on Windows

  • Fix color detection in Emacs tramp

  • col_strsplit and col_substr corner cases:

    • handle empty chunks at beginning or end of strings like base::strsplit (@brodieG, #26)

    • explicitly deal with 'split' values that are not length 1 as that is not currently supported

    • handle zero length x argument in col_substr, and add more explicit error messages for corner cases

  • Some performance improvements to col_substr (@brodieG)

  • Change rgb to ANSI code mapping, based on the "paint" ruby gem (@richfitz, #33, #34)


  • Fixed some R CMD check problems.


  • Colors are turned on by default in Emacs ESS 23.x and above.

  • Functions to turn on and off a style: start, finish.

  • Really fix tput corner cases (@jimhester, #21)


  • Fix detecting number of colors when tput exists, but fails with an error and/or does not return anything useful. (@jimhester, #18, #19)


  • Fix detection of number of colors, it was cached from installation time (#17).

  • Color aware string operations. They are slow and experimental currently.


  • show_ansi_colors() prints all supported colors on the screen.

  • 256 colors, on terminals that support it.

  • Disable colors on Windows, they are not supported in the default setup.


  • First released version.

Reference manual

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


1.4.1 by Gábor Csárdi, 9 months ago

Report a bug at

Browse source code at

Authors: Gábor Csárdi [aut, cre] , Brodie Gaslam [ctb]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports grDevices, methods, utils

Suggests mockery, rstudioapi, testthat, withr

Imported by AgroReg, BCHM, BatchGetSymbols, BayesianFROC, CoTiMA, DHS.rates, DataPackageR, ECOTOXr, EFAtools, ExpImage, GA, GetDFPData, GetoptLong, IMIX, IRkernel, LLSR, MSbox, MarginalMediation, MultivariateAnalysis, NACHO, NIMAA, NMproject, ParBayesianOptimization, R.temis, RFishBC, ReDaMoR, Rtrack, SGP, SGPdata, SPARTAAS, SpaDES.core, TeXCheckR, TestDesign,, VarBundle, WeightIt, WikidataR, aRbs, actuaryr, anomalize, available, babelwhale, baggr, basket, bayesmodels, biocompute, bioseq, boomer, bruceR, bsub, cSEM, cabinets, cascadess, casino, censo2017, ch, cheatsheet, ciu, cleaner, cliapp, cobalt, coinmarketcapr, colorDF, colt, correlationfunnel, corx, covr, cowsay, crunch, cyclocomp, dartR, dash, dbflobr, debugme, desc, dexterMST, diffobj, disk.frame, diveR, do, dtplyr, dundermifflin, dynutils, dynwrap, eplusr, evaluator, fgeo, fiery, findInFiles, findInGit, flatxml, fmtr, foghorn, fpp2, fpp3, future.tests, galigor, garma, geometr, gfonts, gitignore, gmailr, gofCopula, golem, goodpractice, healthyverse, hgutils, idiogramFISH, iheiddown, insee, interactions, isaeditor, jtools, kerastuneR, konfound, libr, lifx, lintr, listdown, lobstr, log, mappoly, metabolighteR, metacoder, miceRanger, microSTASIS, modeltime.resample, msig, multicolor, multidplyr, music, nflseedR, nlrx, noah, obfuscatoR, onc.api, ondisc, openMSE, openVA, orderly, outsider, outsider.base, packagefinder, packager, pak, panelr, partition, peRspective, photosynthesis, piggyback, pillar, pkgbuild, pkgdepends, pkgdown, pkgload, pkgndep, plumber, portalr, ppgmmga, prettycode, progress, promotionImpact, prrd, prt, ralger, ramlegacy, randomNames, rcompendium, rdoc, readit, readr, recombinator, recorder, reporter, rgee, rgovcan, rhub, riingo, rscc, rstac, sars, savonliquide, schoenberg, sdcLog, seecolor, seedreg, semtree, sendgridr, sfnetworks, shiny, shinytest, simfinR, sinew, skimr, sloop, slouch, spaMM, spatialTIME, spsComps, spsUtil, stevedore, studentlife, tabr, tabshiftr, tabxplor, tatoo, taxa, taxize, taylor, tealeaves, testthat, thinkr, tibblify, tidyUSDA, tidycensus, tidyhydat, tidyquant, tidysq, tidyverse, toOrdinal, tracer, tradepolicy, tremendousr, trendyy, trimmer, twenty48, twn, typehint, unitizer, upstartr, usethis, vroom, warbleR, wyz.code.metaTesting, wyz.code.offensiveProgramming, wyz.code.rdoc, xpose.nlmixr, ymlthis.

Depended on by ExpAnalysis3d, LearningRlab, sommer.

Suggested by Infusion, MBNMAdose, MBNMAtime, MSEtool, PMwR, RxODE, SDMtune, STV, bittermelon, blob, catchr, configural, conflicted, crossmap, crosstable, cutpointr, dm, drake, ehelp, exampletestr, fabletools, fs, fst, ghibli, glue, hardhat, haven, healthyR,, healthyR.ts, hms, huxtable, incase, ipaddress, khroma, lgr, lifecycle, logger, logging, mapedit, mark, mclustAddons, meltr, metafor, modeltime.ensemble, multinma, nflfastR, nlmixr, ore, plu, pointblank, potools, prismatic, progressr, psychmeta, purrr, reproducible, rlang, rotor, smerc, symengine, taxadb, taxalight, testthis, tibble, tidyselect, vcr, vctrs, xgboost, yardstick.

See at CRAN