[R] colour highlighting inputs and outputs in the R terminal?

Marc Schwartz marc_schwartz at me.com
Tue Feb 23 15:02:16 CET 2010

On Feb 23, 2010, at 7:05 AM, Liviu Andronic wrote:

> Dear all
> Is it possible to get basic colour highlighting for inputs and outputs
> in the R terminal? I am looking for something similar to what GUIs
> provide, such as JGR and (I think) the Windows R GUI: colouring all
> inputs in red, and all outputs in blue. All this in a colour-aware
> console (in my case, on Linux).
> I've been looking into xterm256 and highlight, but I am sofar unable
> to do with them what I would need. The closest I get to is with
> style() in xterm256:
>> require(xterm256)
>> cat( style( "hello world", bg = "black", fg = "blue"), "\n" )
> hello world
> The text will appear blue. What I would want to achieve, however, is
> to be able to define some global options for input fg and bg colours,
> and output fg and bg colours. Then, for any command that I would
> execute, say `mean(1:5)', I would get:
>> mean(1:10)  ##in red
> [1] 5.5  ##in blue
>> summary(1:5)  ##in red
>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.  ##in blue
>      1       2       3       3       4       5  ##in blue
> Does anyone know a way to do this? Thank you
> Liviu

Hi Liviu,

I was not aware of Romain's xterm256 package, but from a quick review of the manual, it would appear to not support an automated syntax highlighting capability. One seems to need to explicitly print output to the console using his functions to be able to colorize it.

Having used R on Windows, Linux and now OSX over the past 8+ years, I initially used ESS (http://ess.r-project.org/) on Windows and stayed with it on each subsequent platform. The terminal consoles are fine for quick and dirty coding and I will frequently use the terminal on OSX to test code for replying to a post here. But for routine use, I am in ESS, which provides syntax highlighting and so much more.

On Windows and OSX, there are GUI interfaces that members of R Core have kindly provided which provide colorized output, but there is no parallel on Linux, other than third party options.

Rather than using the terminal, I would recommend that you give serious consideration to using a full blown text editor, many of which already support R syntax highlighting and of course typical text editing features. In the most basic implementation, you can write your code in the editor and copy and paste it to the R console. 

With tighter integration, such as ESS, you can have split windows, with R code in one frame (say the upper half of the application window) and the R console running in an other one (say the lower half), both of which support R syntax highlighting. With a quick few keystrokes, you can submit the entire R code frame to the console or highlight sections of code and just submit that. Beyond that there is a lot other functionality (version control, LaTeX support, etc.) available that makes ESS an extremely efficient environment to use.

If you prefer to not use or learn Emacs, there are other editors available such as Vim, Bluefish, Eclipse and many others available for Linux, some of which are listed here:


JGR is also available for Linux:



Marc Schwartz

More information about the R-help mailing list