tableone icon indicating copy to clipboard operation
tableone copied to clipboard

Facilitating latex output of tableone object

Open guru1982 opened this issue 9 years ago • 7 comments

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

guru1982 avatar Feb 05 '16 08:02 guru1982

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")

kaz-yos avatar Feb 06 '16 19:02 kaz-yos

Just a comment, that the approach desribed above works beautifully when passed to pander::pander or knitr::kable for use with knitr and rmarkdown.

tormodb avatar Feb 24 '16 07:02 tormodb

Thanks for your information!

kaz-yos avatar Feb 24 '16 12:02 kaz-yos

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 avatar Aug 23 '17 08:08 elisanapo

@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?

ellereve avatar Feb 26 '18 12:02 ellereve

Can you try print(..., printToggle = FALSE) to suppress printing of the formatted tables?

kaz-yos avatar Feb 26 '18 13:02 kaz-yos

Hi! Thank you so much for your effort in making this work. Have there been any updates regarding compatibility with xtable?

martinezsebastian avatar Aug 26 '19 07:08 martinezsebastian