Is there a way to output text to the R console in color

RColorsConsoleOutput Formatting

R Problem Overview


I am writing a script and I want to output text messages to the console with different colors depending on conditions. For example: RED for errors and BLUE for warnings, etc.

I am using RStudio.

R Solutions


Solution 1 - R

Check out the new crayon package:

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

More info on the GitHub page.

Works in RStudio 1.2.360+

Solution 2 - R

The xterm256 package by Romain Francoise allows this sort of thing in general on any console that understands xterm256 interrupts.

Solution 3 - R

On either Linux or Mac, you could try https://github.com/jalvesaq/colorout It doesn't work on Windows.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnotuoView Question on Stackoverflow
Solution 1 - RkrlmlrView Answer on Stackoverflow
Solution 2 - RGavin SimpsonView Answer on Stackoverflow
Solution 3 - RAquinoView Answer on Stackoverflow