Skip to content
Prev 303083 / 398506 Next

export table in separate file

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: