rcolorsconsoleoutput-formatting

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


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.


Solution

  • Another option could be using the insight package with the print_color function. You could also make the text bold or italic. Here is some reproducible code:

    library(insight)
    print_color("ERROR", "red")
    print_color("WARNINGS", "blue")
    

    Output RStudio:

    enter image description here