tableone
tableone copied to clipboard
Facilitating latex output of tableone object
Hi. Tableone is great package. But it however requires copy pasting in excel. Is it possible to enable latex output such as seen with "xtable" package? Thanks in advance
xtable integration is on my agenda, but it has not been implemented. However, you can exploit the matrix output and pass it to xtable. This does not format well, so you will need some manual adjustment
## The print method returns a matrix.
tabAsStringMatrix <- print(TableOneObject, printToggle = FALSE, noSpaces = TRUE)
## Very crude, but it can work.
xtable(tabAsStringMatrix)
## Also exporting to .csv can be automated.
write.csv(tabAsStringMatrix, file = "tab1.csv")
Just a comment, that the approach desribed above works beautifully when passed to pander::pander or knitr::kable for use with knitr and rmarkdown.
Thanks for your information!
Just stumbled upon this thread while trying to export a TableOne object into an html Rmarkdown. I followed the instructions above, but the exported table only included the means and SDs instead of all the other stats that can be included in a TableOne object.
I have found a solution to this, which is to coerce the TableOne object to a dataframe with as.data.frame.list and then use knitr::kable to include in html Rmarkdown. It worked for me!
@elisanapo, I wonder how you did that exactly. I wanted to combine to TableOne objects, so I used print() on both then cbind and then pander. However, I get the proper rmarkdown table, but also the 2 smaller unformatted tables even though I had assigned them to something like tab01 and tab1. Any ideas?
Can you try print(..., printToggle = FALSE)
to suppress printing of the formatted tables?
Hi! Thank you so much for your effort in making this work. Have there been any updates regarding compatibility with xtable?