user1471980
user1471980

Reputation: 10626

how do you print xtable using knitr in word document

I am trying to print xtable in using knitr in word document as follows:

library(knitr)
library(xtable)
  p1<-xtable(head(iris), include.rownames=FALSE, floating=FALSE)
  print(p1)

I get this error, any ideas:

latex table generated in R 3.2.2 by xtable 1.7-4 package % Mon Oct 26 11:17:22 2015

Upvotes: 2

Views: 4105

Answers (1)

Benjamin
Benjamin

Reputation: 17369

I don't think you can do this with the standard word_document that comes with rmarkdown. xtable only produces output in HTML and LaTeX formats. To render a word document, your table has to be prepared in markdown format (so far as I know).

Some alternative options are to use knitr::kable or the pixiedust package.

If you're comfortable downloading things from GitHub, you may also use devtools::install_github("gforge/Grmd") and then replace output:word_document with output: Grmd::docx_document. Then using print.xtable with type = 'html' will render to an HTML document that can be opened as a docx.

Upvotes: 2

Related Questions