R knitr print in loop

I used the xtable package to create HTML tables from R-matrices. When I used the kable function in a loop, it did not output anything. So I looked with the print function, which worked. The problem is that when I use the print function, I get a lot of "##" printed along the HTML table. Is there a way to print my kable, but avoiding "##" per line in a loop?

 library("xtable", lib.loc="~/R/win-library/3.1") for(i in 1:3) { #Must use print because of the loop, but get ## per line print(kable(head(cars), "html", table.attr='class="flat-table"')) } #No neded to use print, no ## printed per line kable(head(cars), "html", table.attr='class="flat-table"') 
+7
loops r knitr
source share
1 answer

You have to say a piece to use the results as is.

Do this by adding results='asis' to the block header.

Try the following:

 ```{r, results='asis', echo=FALSE} library(knitr) library(xtable) for(i in 1:3) { #Must use print because of the loop, but get ## per line print(kable(head(cars), "html", table.attr='class="flat-table"')) } ``` 

You should get

 speed dist 4 2 4 10 7 4 7 22 8 16 9 10 
+8
source share

All Articles