isubirana / compareGroups

R package to easily build publication-ready univariate or bivariate descriptive tables from a data set.
https://isubirana.github.io/compareGroups/
34 stars 13 forks source link

Export to flextable #39

Closed acebollada80 closed 2 months ago

acebollada80 commented 5 months ago

HI!

I would like to know if there is a way to export a compareGroups object into the flextable format for easier table visualization and reporting. Is this functionality currently supported, or are there any recommended approaches to achieve this?

Thank you!

Alberto Cebollada

isubirana commented 5 months ago

Hi Alberto.

By default, export2md function returns and object of class kable. But if you set the format to 'markdown', the resulting table will be of class "flextable" to which all function of this package can be applied. For example, to colour the first row to red on a descriptive table of iris data:

library(compareGroups)

tab <- export2md(descrTable(iris), format="markdown")
class(tab)

flextable::bg(tab,i = 1,bg = "red")

In summary, export2md uses knitr and kableExtra when exporting to HTML or LaTeX, and flextable when exporting to markdown or Word.

Kind regards,

Isaac.