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

How to print kable output to pdf in a loop

$
0
0

I am trying to print tables to a pdf from a loop and am having no luck what-so-ever. I originally was using Flextable but saw comments online that not being able to do this was a problem with it. So, I switched to Kable and Kableextra. I still am having no luck in making this work. There are some threads out there that suggest various things. I have tried them all and nothing seems to work for me. So, I created a really simple example of where I am and I am hoping that someone will be able to show me how this is done.

This is RMarkdown code.

---title: "test_print"output: pdf_document---
knitr::opts_chunk$set(echo = FALSE)library(kableExtra)
#create a list and put two kables in itlst <- vector("list", 2)lst[[1]] <- kbl(head(cars), booktabs = T)lst[[2]] <- kbl(head(pressure), booktabs = T)
lst[[1]]  #this code works fine producing a table in the pdf file
for (i in 1:2){  lst[[i]]   #this code produces no output at all}
#this produces a shiny tag list with the reports seemingly there but they do not output properlyfor (i in 1:2){  print(lst[[i]])  }

There have been various suggestions online for how to fix this but I have not been able to get any to work. For instance, in several places it says that you have to wrap the kable in print as the side effects do not work properly in a loop.

I am new to R and RMarkdown, so I could be missing something simple here, but enough other people have had problems with this as well (given the threads I found) so perhaps it is not so simply after all.

I would appreciate and ideas on how to solve this.


Viewing all articles
Browse latest Browse all 106

Trending Articles



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