[R] outputing text colors

Jakson A. Aquino jaksonaquino at gmail.com
Sat Mar 20 02:17:50 CET 2010


On Thu, Mar 18, 2010 at 11:27:40PM -0800, rtist wrote:
> 
> Hi Everyone,
> 
> And thanks for the replies.  I was more specifically referring to the
> console table output itself.
> I have a time series that has columns of months and rows of years, and each
> row,col is a value.
> I wanted the actual text output value to the console table r,c to have a
> color corresponding to the value,
> like ifelse(val<0,txt="red",txt="green"), so that I can quickly have an
> overview of returns by color.
> 
> It looks like the only solution is to use a literal graphics object, and
> that the above solution is not feasible.
> I'll look into the graphical type objects.  It would be nice to have a
> function that simply reads a time series
> object table<-f(ts.table) and outputs the above criteria.

It's possible to do it (at least in a Linux terminal emulator)
with the package xterm256. However, the default print function
does not print the scape sequences which the terminal emulator
interprets as colors. It would be necessary to create a print
method for ts.table (or any other object to be printed in color).
Simple example:

library(xterm256)
x <- style(c(-1, 0, 1), fg = c("red", "blue", "green"), check.xterm = F)
cat(x, "\n")
print(x)

-- 
Jakson A. Aquino
Federal Uni. of Ceara
www.lepem.ufc.br - Brazil



More information about the R-help mailing list