How to produce HTML tables and accompanying CSS using R Markdown or HTML Sweave?

前端 未结 5 1705
夕颜
夕颜 2021-02-06 04:13

I previously asked a question about how to export a HTML table in R and have control over line borders.

I\'m used to LaTeX where when you create a table, the formatting

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 04:25

    An alternative method would be to use pander as R markdown backend (sorry for this marketing-like answer, but I do think my Pandoc.brew function could be really handy for this purpose).

    It is similar to knitr (parsing/evaling R commands in a markdown formatted file) but using brew syntax for R code blocks (e.g. <%...%> for general R code - like loops etc. and <%=...%> for returning results in a block). But differs from brew as Pandoc.brew does not only cat results in a code block, but runs my pander generic method which transforms (quite q wide variety of) R objects to (IMHO) pretty Pandoc's markdown format.

    So running Pandoc.brew on a markdown formatted file would result in a clean markdown file with all R code blocks run - and you do not have to deal with xtable and other tweaks (not even with plots as all R code blocks resulting in an image is rendered to a png file and linked in the markdown text file).

    And about why I started to answer here: with pander you can pass special options to pandoc, e.g. adding a custom CSS stylesheet (or JS etc.) to your generated HTML's header, see details on Pandoc's homepage. Based on that you could easily add your CSS file(s) or even just a bunch of style parameter. This could be done in pander with Pandoc.convert's option. BTW you do not even have to use my forked brew function, you can generate your markdown file with e.g. knitr and call Pandoc with the above function.

    pander adds some CSS/JS to generated HTML files, which would generate (IMHO) quite pretty output, but you can easily customize that and adding your own files there.

    For example: you would get this HTML file based this markdown by default which was Pandoc.brewed from this quite short markdown syntax brew file. BTW my github page was also generated/automatically styled by my markdown parser. I would really appreciate if you would try it :)


    NOTE: to try the above calls you would need Pandoc pre-installed, also you'd need an up-to-date version of both rapport, both pander. See installation details.

提交回复
热议问题