[R] DISPLAYING TABLE in file

Marc Schwartz marc_schwartz at me.com
Fri Mar 26 03:06:39 CET 2010


On Mar 25, 2010, at 8:01 PM, Rolf Turner wrote:

> 
> On 26/03/2010, at 1:36 PM, Geddes, Scott wrote:
> 
>> 
>> Hi,
>> 
>> I wish to NEATLY store, and later display one table per file (similar to
>> capabilities of write.table()).
>> 
>> BUT BY NEATLY I MEAN:
>> 1. Column Headings right aligned with data values.
>> 2. Decimal points line-up per column.
>> 3. Data values padded trailing zeros per column (if not integers).
>> 4. "Tricky" formats such as certain characters/dates possibly chosen by
>> the user?
>> 
>> bla bla bla 
>> 
>> I do not care about increased memory storage but my main concern is to
>> DISPLAY contents of file.
> 
> 
> If by ``table'' you mean data frame, you can get most (???) of what you want
> by doing:
> 
> sink("neat.txt")
> print(xxx,row.names=FALSE)
> sink()
> 
> To get things exactly as you want them, you might have to mess around
> using sprintf() on the (numeric) columns of the data frame xxx before
> printing it.  There is almost surely nothing ``off the peg'' that does
> exactly what you want.


I would also just point out that at least from the perspective of later displaying the content of a text file stored in this fashion, it also depends upon the use of a fixed width (monospace) font for output. That information is not stored in a regular text file, thus is dependent upon the font used by application that the file is displayed within. If the application uses Arial or Times Roman, for example, all of your columnar spacing alignments will be off. 

If you are going to use the R console for the output and you have no control over what a user may alter with respect to the default font used, that can be an issue.

If you don't need a user to actually manipulate the stored/formatted data, but simply display it, you might want to look into using Sweave (R + LaTeX), which would let you generate publication quality tabular output to a PDF file. If interested, then take a look at the xtable package on CRAN and the latex() function in the Hmisc package on CRAN. You can get a sense of what can be done by reviewing this document from Frank Harrell:

  http://biostat.mc.vanderbilt.edu/wiki/pub/Main/StatReport/summary.pdf

HTH,

Marc Schwartz



More information about the R-help mailing list