Quantcast
Channel: Active questions tagged kable - Stack Overflow
Viewing all articles
Browse latest Browse all 109

rmarkdown using kable with list of data.tables loses table formatting

$
0
0

I have a rmarkdown document where I want to use a list of data.tables 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.tables 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.

enter image description here

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.

enter image description here

Further, if I just pass the list of data.tables 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:

enter image description here

Does anyone know why is this happening and how can I overcome this issue?


Viewing all articles
Browse latest Browse all 109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>