R: why kable doesn't print inside a for loop?
<p>I'm working a report with rmarkdown and latex. I need to print a group of tables using <code>knitr::kable</code>, but the don't print when inside a for loop.</p>

<p>This is my code:</p>

<pre><code>---
title: "project title"
author: "Mr. Author"
date: "2016-08-30"
output: 
  pdf_document: 
    latex_engine: xelatex
bibliography: biblio.bib
header-includes:
   - \usepackage{tcolorbox}
---

Text and chunks that run ok.

```{r loadLibraries}
require(data.table)
require(knitr)
```

## Try to print a group of tables from split

```{r results = "asis"}
t1 &lt;- data.table(a = sample(letters, 10, T), b = sample(LETTERS[1:3], 10, T))
t2 &lt;- split(t1, t1$b)

for (i in 1:length(t2)){
    kable(t2[[i]], col.names = c("A", "B"))
}
```
</code></pre>

<p>It doesn't matter if I use <code>results = "asis"</code> or if I omit it altogether, <strong>nothing prints to the document</strong>.</p>

<p>I've tried enclosing the <code>kable</code> call within a <code>print</code> call (<code>print(kable(t2[[i]]...</code>), and it successfully prints the output to the document, but the format is the same format as a standard R prompt (preceded by <code>##</code>, for example), which is rather ugly.</p>

<p>How can I display the tables, other than manually?</p>

<p><strong>### EDIT ###</strong></p>

<p>Some answerers have redirected me to <a href="https://stackoverflow.com/questions/28313600/r-knitr-print-in-a-loop">R knitr print in a loop</a> as a duplicate answer. <strong>It's not</strong>, because as I stated in the previous paragraph, this effectively prints the table, <em>but the format is not the expected one</em>. The accepted answer (and related github thread) really solved the problem.</p>