4

How do I create multiple outputs via pander() in a knitted document "asis" ?

When I have multiple calls of pander in a function, only the most recent one is shown in the HTML output. Here's an example:

tmp = function() {
  pander('A')
  pander('B')
  pander('C')
}
tmp()

In the knitted document this gives: C

I could set panderOptions('knitr.auto.asis', FALSE) or I could use cat() so that the pander() output is written to the standard output. But then it's formatted as code, not as part of the document. As I need pander() to format a few tables for me, this does not help.

daroczig
  • 28,004
  • 7
  • 90
  • 124
BurninLeo
  • 4,240
  • 4
  • 39
  • 56

1 Answers1

3

The tmp function will return only the last object -- that's why only C is printed. If you want to write each object to the stdout right away without the auto-asis convenience option, then you have to both disable the option like you did and use the relate knitr chunk option, eg:

```{r results='asis'}
library(pander)
panderOptions('knitr.auto.asis', FALSE)
tmp = function() {
  pander('A')
  pander('B')
  pander('C')
}
tmp()
```

See more examples in the related "Using pander with knitr" vignette.

daroczig
  • 28,004
  • 7
  • 90
  • 124