22

I've used knitr and LaTeX but I'm thinking of changing to Markdown as this seems more compatible with Word (htlatex and Pandoc work but it's far from comfortable). My current problem is finding an alternative to latex() in the Hmisc package. The only alternative I've found is xtable, but it doesn't seem to create multicolumns.

Here's an example:

mx <- matrix(1:6, ncol=3) 
rownames(mx) <- LETTERS[1:NROW(mx)] 
colnames(mx) <- sprintf("Col %s", LETTERS[1:NCOL(mx)])
latex(mx, n.rgroup=c(2), rgroup=c("Nice!"),
      n.cgroup=c(2,1), cgroup=c("First", "Second"),
      file="", 
      ctable=TRUE)

produces this table:

enter image description here

Max Gordon
  • 5,367
  • 2
  • 44
  • 70
  • 1
    Of course you can create multicolumns with `xtable` ... see e.g., [here](http://stackoverflow.com/a/32490565/3162788) or [here](http://stackoverflow.com/a/28420723/3162788). – ToJo Sep 09 '15 at 23:23

1 Answers1

26

Ok, so I wrote it myself...

The package is as of version 1.0 called htmlTable and is available both from CRAN and and my blog, gforge.se/packages. I hope you find it useful. I've created a few vignettes to help with all the options.

Max Gordon
  • 5,367
  • 2
  • 44
  • 70
  • 3
    I think you can mark this as the answer. At least I'm not aware of any packages that do this job. – Yihui Xie Aug 15 '12 at 16:09
  • 1
    @Yihui Thanks. I'm considering writing a package that contains and some other functions that I haven't located. It surprises me though that there isn't a package that does this since you can't publish anything without proper tables. I'll mark this as answered as soon as I'm allowed (in 15h) and I'll get back with the final version once I'm done with the first version of my package. – Max Gordon Aug 15 '12 at 19:08
  • @MaxGordon, this looks interesting, and I definitely agree to your point about 'you can't publish anything without proper tables.' Have you made a package? – Eric Fail Nov 28 '12 at 21:49
  • 1
    @MaxGordon, I like the function, thanks. I believe there is a bug there is a bug which causes markdown to fail in certain cases. There is a nbsp without a semi-colon at the end, at line 39. JPhilip –  Dec 03 '12 at 19:02
  • @jphilip, thanks for the feedback - glad you like it. I've updated the package with the bug-fix, ver 4.3. – Max Gordon Dec 04 '12 at 19:44
  • 1
    Sorry for excavating this ancient question, but is it correct that `htmlTable` cannot be used to directly generate a Word document from rmarkdown? I only see how it is possible to generate HTML and copy-paste this into Word. – CL. Feb 11 '16 at 12:31
  • 1
    @CL. correct - unfortunately pandoc can't handle advanced html-syntax – Max Gordon Feb 11 '16 at 13:55