Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 899
notuo Avatar asked May 29 '12 16:05

notuo


People also ask

How do you change the color of the console in R?

In RStudio under tools -> Options -> Appearance you can change the color of your R console and also change the fonts.

How do you save a console output to a text file in RStudio?

You can also save the entire R console screen within the GUI by clicking on "Save to File..." under the menu "File." This saves the commands and the output to a text file, exactly as you see them on the screen.

How do I print to console in R?

Every language provides some functions that can help you print the data on the console, and R is no different. To print the data on the console in R, use the print() function.

How do I copy text from the console in R?

I just found a solution that works at least on my present OS, Linux Mint (19.3): Just select text and click with middle mouse button to the place (e.g. in WPS Office or LibreOffice) where you want to copy-paste the selected text. It will instantly copy and paste the text without formatting.


1 Answers

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+

like image 167
krlmlr Avatar answered Sep 22 '22 19:09

krlmlr