Re: [R] Transfer Crosstable to Word-Document

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun, 17 Feb 2008 09:16:50 -0500

On Feb 17, 2008 8:20 AM, Gabor Grothendieck <ggrothendieck_at_gmail.com> wrote:
>
> On Feb 17, 2008 4:41 AM, Peter Dalgaard <p.dalgaard@biostat.ku.dk> wrote:
> >
> > Gabor Grothendieck wrote:
> > > On Feb 16, 2008 5:28 PM, David Scott <d.scott_at_auckland.ac.nz> wrote:
> > >
> > >> On Sat, 16 Feb 2008, Alan Zaslavsky wrote:
> > >>
> > >>
> > >>> If you want to get nicely formatted tables in Word and are familiar with
> > >>> Office tools (I know it's the Evil Empire but some of us work there), I
> > >>> suggest that you use Excel for formatting and then insert the table into
> > >>> your Word document. IMHO, Excel is much superior to Word for table
> > >>> formatting, e.g. modifying number of significant digits, playing around
> > >>> with fonts and number formats, etc. And when you have gotten the formats
> > >>> right you can paste in modified values of the numbers in the table without
> > >>> having to do the formatting again. Including the table in your Word
> > >>> document is easy by cut-paste or creating a live link.
> > >>>
> > >>> As a user of R under Unix I haven't looked into the facilities for writing
> > >>> tables to Excel under Windows but there is something there. Alternatively
> > >>> you can write a fixed-column or tab-delimited file and easily import to
> > >>> Excel.
> > >>>
> > >>>
> > >> Production of tables and formatting them in Word is something I have dealt
> > >> with a couple of times recently and it really is important to do something
> > >> smart because of the time taken to individually format tables.
> > >>
> > >> An approach I used recently was to produce a text table in R and export it
> > >> to Excel as a .csv file which could then be copied as is to Word. Borders
> > >> and the like would still have to be formatted individually but not entries
> > >>
> > >
> > > You could get a border automatically by writing your table out
> > > as HTML. Try this using the builtin data frame iris:
> > >
> > > library(R2HTML)
> > > HTML(iris, border = 1, file("clipboard","w"), append=FALSE)
> > >
> > > Now paste that into Excel and from Excel into Word and you should
> > > have a border around it.
> > >
> > > See ?HTML.data.frame
> > >
> > > You could alternately generate the HTML yourself giving quite a bit
> > > of control.
> > >
> > Just curious (I don't use Word if I can help it -- even the simplest of
> > things drive me up the wall), but can you not import HTML directly in
> > Word? OpenOffice seems to do it quite happily with xtable output.
>
> You can open an HTML file in Word as a new document and it will
> be properly formatted and then you could save that document as
> a Word document and insert it into your main Word document.
> Alternately, you could copy and paste it from the newly created Word
> document into your main Word document and that would preserve formatting.

Actually you could alternately read the HTML file into Word with formatting preserved using

   Insert > Object > Create From File
(that's in Word 2007; I think the menus are slightly different in earlier versions) and not use the clipboard at all. That's a bit of a nuisance due to the requirement of creating the intermediate file and having to browse to it in Word. Thus pasting it into Excel and then Word is probably still the fastest but this would be a viable alternative and would be superior if you wanted to generate many tables in R at once and then later add them to Word.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 17 Feb 2008 - 14:50:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 17 Feb 2008 - 15:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive