[R] export table in separate file

Duncan Mackay mackay at northnet.com.au
Sat Aug 11 00:33:26 CEST 2012


Hi

Here is some code I used to produce an html table file within my 
Sweave chunk .
I needed to produce html tables to go into word as well as producing a pdf

     file.create(fhtml) # file name

     # open to append
     ff <- file(fhtml, "a+")

     # Table
     fchars <-
     c('<TABLE align="center" border="0">\n',
       '<CAPTION>\n',
       "Ewe numbers by date, year born, and year group",
       '</CAPTION>\n')

     writeLines(fchars, ff)

     # print xtable
     fchars <-
     print(
     xtable(xx[,-1]
            ),
            type    = "html",
            html.table.attributes = "border = '0'",
            include.rownames = FALSE,
            include.colnames = FALSE,
            only.contents = TRUE, #NA.string = " ",
            hline.after = NULL
     ) ## xtable

     writeLines(fchars, ff)

     # Close
     writeLines('</TABLE>\n</HTML>', ff)
     close(ff)

Some may tut tut about it but it is easy for me to make templates 
which I can vary - not all output required is simple

HTH

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

At 02:40 11/08/2012, you wrote:
>Hi Folks,
>
>I'm using Sweave to generate png & pdf graphics that I then "Import &
>Link" in a Word document.  This let's me create sharable and editable
>dynamic documents.  They are dynamic in that I can regenerate figures
>when the data changes, and have those figures automatically updated in
>my Word doc since they're "linked", and not just "imported" in Word.
>
>I want to do the same for tables.  Right now, I've rolled my own
>function to turn tables into a png.  However, I would like a more robust
>solution.  Is there any way I can turn tables into, say, an HTML table
>in a separate file that could be linked in Word?  I know one can create
>HTML tables in Sweave and otherwise.  The difference is that I need
>those tables to exist each in their separate file.
>
>Any thoughts would be much appreciated.
>
>Thanks,
>Allie
>
>______________________________________________
>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.



More information about the R-help mailing list