Reputation: 380
Is there any way that I can change the output color in R.
Let for example
> y="red color"
> z=5<3
need some command that will print the value of y in red color, and/or value of z in red. Is it possible in simple way?
Upvotes: 4
Views: 5139
Reputation: 829
There is a package called 'crayon' (https://github.com/gaborcsardi/crayon). It allows you coloring outputs. Unfortunately, the RStudio console can't display these colors yet. Examples from crayon package:
library(crayon)
#test1
cat(blue("Hello", "world!\n"))
#test2
cat(green(
'I am a green line ' %+%
blue$underline$bold('with a blue substring') %+%
' that becomes green again!\n'
))
Upvotes: 2
Reputation: 9656
For general coloring of output there is a package called colorout. It says that in order to change the color of R output you would have to rewrite the outputing functions.
It is not available on CRAN, but you can download and install it from github. Then simply load the package library(colorout)
If you only want specific outputs colored (instead of all R output) I guess you might try looking through the source of colorout: https://github.com/jalvesaq/colorout/blob/master/R/colorout.R and writing your own output function.
Upvotes: 2