rknitrr-markdownpander

Rmarkdown Not Producing Table Within For In Loop


I'm trying to produce an automated report using Rmarkdown. In this report I have sections with tables. The sections are produced using the following Rmarkdown. However, it refuses to produce any tables(tried using kable and pander) when I hit knit. Knit will just produce the headings, without any tables. When I use the immediate mode, I get the appropriate markdown. So what might I be doing wrong.

```{r, results='asis'}
for(p in names(presentations)) {
  deats <- presentations[p][[1]]
  cat('#', p, '\n')
  pander(deats)
  str(deats)
  cat('\n')
}
```

Solution

  • If using pander, disable the auto asis results:

    ```{r, results='asis'}
    library(pander)
    panderOptions('knitr.auto.asis', FALSE)
    
    for(p in names(mtcars)) {
      cat('#', p, '\n')
      pander(table(mtcars[, p]))
    }
    ```
    

    For more details, see the related Using pander with knitr vignette