Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in R / RStudio running on Windows, can we make message(), warning() and error() use different colors in the console?

I use a lot of messages e.g. message("dadida") in one of my projets, and it is becomming annoying to see all this red text everywhere, always making me wonder if there's an error or a warning hidden somewhere.

I need those messages in the end product so I can't just remove them. But if there was a way to make messages, warnings and errors appear in different colors in the console, that would solve my problem. I haven't found a way to do this.

Edit

Thanks all for your input. I hadn't realized that the red color for all those types of messages was specific to RStudio. In the RGui, all is just plain white text. If customizing the colors is not feasible in RGui, maybe it is in RStudio?

like image 991
Dominic Comtois Avatar asked Sep 29 '22 10:09

Dominic Comtois


1 Answers

While I am not aware of a way of customizing the output in RGui or RStudio for Windows, using cat() instead of message() will avoid the red text in RStudio. Instead of using

message("Hello!")

use

cat("Hello!\n")

(note the \n that is needed to get a new line).

There are some subtle differences between message() and cat(), which may be relevant when you are redirecting your output e.g. to a LaTeX document using Sweave, so cat() may not be a suitable substitute in all settings.

like image 93
Rob Hall Avatar answered Oct 02 '22 15:10

Rob Hall