[R] formatted table to disk

Randy Zelick zelickr at pdx.edu
Wed Apr 21 17:10:53 CEST 2004

Hello there,

Using R 1.8.1 and WinXP...

I would like to write a disk file (ascii text) of an R data frame. When I
type the name of the object in the console window, it is sensibly and
nicely formatted. When I use write.table, it is *not*, because the
separation character is just a space.

I looked through the introductory material (my level) on the R website,
but did not find a reference to this issue.

At a minimum I suppose there is a way to insert a tab character in the
sep=" " field, but I don't know how to do that. Alternatively, I could
deal with a variable specifying fixed-field widths for each of the
variables in the frame. Didn't find that either.

Even so, you would loose the right-justification and the fact that R seems
to take into account the width of the largest value in a column.

Of course the really slick deal would be to have paginated output where
the column titles repeat at the top of the page (having entered a
parameter for the number of lines on your page after margins and so

A somewhat brutal solution would be to create all the text strings for
making a LaTex document/table environment and write all that stuff out to
the text file. Please don't tell me I have to do that!

So is there a function for producing a file on disk with the same
formatting as the screen?



R. Zelick				email: zelickr at pdx.edu
Department of Biology			voice: 503-725-3086
Portland State University		fax:   503-725-3888

P.O. Box 751
Portland, OR 97207

1719 SW 10th Ave, Room 246
Portland, OR 97201

More information about the R-help mailing list