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: mac...@northnet.com.au

At 03:10 9/11/2012, you wrote:
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 <xieyi...@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 <wewol...@gmail.com> wrote:
> Hi,
>
> So far I used Sweave to create pdf reports. I used xtable to create some
> tables in the report.
>
> But now I would like to use the same snw file to generate an HTML version.
> The xtable output breaks the RweaveHTML driver.
> library(R2HTML)
> Sweave('analyseLFQ.Snw', driver = RweaveHTML)
>
> Error in match.arg(options$results, c("Robj", "html", "hide")) :
>   'arg' should be one of "Robj", "html", "hide"
>
> Any suggestions would be highly recommended. I.e. I am wondering can I
> include dynamically generated tables in Sweave output,
> using syntax independent of the renderer?
>
>
> regards
> Witold
>
>
>
>
> --
> Witold Eryk Wolski
>
> Triemlistrasse 155
> 8047 Zuerich
>

______________________________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to