I have a rmarkdown
document where I want to use a list of data.table
s and include them in a PDF/HTML/MS Word document. Each component of the list contains one data.table
.
What I'm trying to achieve is to use kable
to add all tables in a document with captions.
When I index the data.table
s one by one like this
```{r} kable(list.of.dts[[1]], caption = paste0("Frequency table for the '", colnames(list.of.dts[[1]])[2], "' variable."))```
everything is fine and the table is nicely formatted as on the screenshot below.
However, if I try to use lapply
to kable
all the data.tables
in the list like this
```{r}lapply(X = list.of.dts, FUN = function(i) { kable(x = i, caption = paste0("Frequency table for the '", colnames(i)[2], "' variable."))})```
to process all data.tables
and include them in the document, I get quite basic and crude output like on the screenshot below.
Further, if I just pass the list of data.table
s to kable
like this
```{r}kable(list.of.dts)```
I get all the tables with a better formatting (although not as in the first example), but stacked on top of each other, centered in the middle of the page and I can't add captions:
Does anyone know why is this happening and how can I overcome this issue?