Skip to content

sweave xtable and driver RweaveHTML

3 messages · Witold E Wolski, Yihui Xie, Duncan Mackay

#
You can certainly generate an HTML table, but how about the rest of
your Snw document? How are you going to convert them to HTML? I mean
otherwise you get something like this which is not a valid HTML
document:

\documentclass{article}
\begin{document}
<TABLE border=1>
<TR> <TH>  </TH> <TH> Sepal.Length </TH> <TH> Sepal.Width </TH> <TH>
Petal.Length </TH> <TH> Petal.Width </TH> <TH> Species </TH>  </TR>
  <TR> <TD align="right"> 1 </TD> <TD align="right"> 5.10 </TD> <TD
align="right"> 3.50 </TD> <TD align="right"> 1.40 </TD> <TD
align="right"> 0.20 </TD> <TD> setosa </TD> </TR>
  <TR> <TD align="right"> 2 </TD> <TD align="right"> 4.90 </TD> <TD
align="right"> 3.00 </TD> <TD align="right"> 1.40 </TD> <TD
align="right"> 0.20 </TD> <TD> setosa </TD> </TR>
   </TABLE>
\end{document}


It is not easy to write a document for both LaTeX and HTML, although
the R output can be easily converted to either LaTeX or HTML.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
On Thu, Nov 8, 2012 at 4:29 AM, Witold E Wolski <wewolski at gmail.com> wrote:
#
Hi

I have sometimes had to produce an html table in Sweave for a 
complicated table and have make a chunk of it .
cut down version below.
You could use the defaults for write.table

     fhtml <-
     paste(baseRimg, "-T", ".html", sep = "")
     if (file.exists(fhtml) ) file.remove(fhtml)
     file.create(fhtml)

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

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

     writeLines(fchars, ff)

     # print xtable
     fchars <-
     print(
     xtable(xx
            ),
            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)

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 03:10 9/11/2012, you wrote: