Reputation: 10401
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?
Upvotes: 5
Views: 1640
Reputation: 182
To make error and warning messages print in a specific color in RStudio, you have to edit your editor theme.
.rstheme
.my_theme.rstheme
.my_theme.rstheme
with a text editor/* rs-theme-name: Example name */
. Replace that with a new title for your theme: /* rs-theme-name: My theme */
..GD15MCFCOTB{color: #FF0000;}
replacing #FF0000
with whatever hex color code you want to use.(I have no idea why, but the CSS class GD15MCFCOTB
is what RStudio uses to designate warning and error messages. I discovered this by right clicking on an error message in RStudio and using the HTML inspector.)
.rstheme
file.Add...
.rstheme
file you created earlier and click Open
.See this page for more info on custom themes in RStudio: https://support.rstudio.com/hc/en-us/articles/115011846747-Using-RStudio-Themes#custom-editor-themes
Upvotes: 2
Reputation: 1418
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.
Upvotes: 3