kaz-yos / tableone

R package to create "Table 1", description of baseline characteristics with or without propensity score weighting
https://cran.r-project.org/web/packages/tableone/index.html
214 stars 40 forks source link

Facilitating latex output of tableone object #10

Open guru1982 opened 8 years ago

guru1982 commented 8 years ago

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

kaz-yos commented 8 years ago

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")
tormodb commented 8 years ago

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

kaz-yos commented 8 years ago

Thanks for your information!

elisanapo commented 7 years ago

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!

ellereve commented 6 years ago

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

kaz-yos commented 6 years ago

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

martinezsebastian commented 5 years ago

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