1

I'm trying to print the outcome of an anova like so:

library(pander)
m.aov = aov(Sepal.Width ~ Species * Sepal.Length, iris)
pander(m.aov, split.table=Inf)

and I get this as expected if I type it into the console:

----------------------------------------------------------------------
                       Df   Sum Sq   Mean Sq   F value   Pr(>F)  
-------------------------- ---- -------- --------- --------- ---------
       **Species**          2    11.34     5.672     76.48   2.329e-23

     **Sepal.Length**       1    4.769     4.769     64.3    3.368e-13

 **Species:Sepal.Length**   2    1.513    0.7566     10.2    7.19e-05 

      **Residuals**        144   10.68    0.07417     NA        NA    
----------------------------------------------------------------------

Table: Analysis of Variance Model

However, if I embed this into a knitr chunk, I don't get the table:

```{r, results='asis'}
library(pander)
m.aov = aov(Sepal.Width ~ Species * Sepal.Length, iris)
pander(m.aov, split.table=Inf)
```

Knit the above and one obtains

```r
pander(m.aov, split.table=Inf)
```

i.e., the code chunk with no output.

Question: Is this a bug (in knitr? pander?) or something I've overlooked? How can I work around it?


> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8       
 [4] LC_COLLATE=en_AU.UTF-8     LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] knitr_1.8      pander_0.5.1   vimcom_1.0-0   setwidth_1.0-3 colorout_1.0-3

loaded via a namespace (and not attached):
[1] digest_0.6.4   evaluate_0.5.5 formatR_1.0    Rcpp_0.11.2    stringr_0.6.2  tools_3.0.2   
mathematical.coffee
  • 55,977
  • 11
  • 154
  • 194
  • You have a typo: pass `m.aov` to `pander` instead of `aov`, and please try running the same with the most recent (dev) version of `pander`: https://github.com/Rapporter/pander/#installation – daroczig Dec 11 '14 at 12:51
  • apologies; I did have `m.aov` in my script, just typo'd it copying it over. The behaviour is present with pander 0.5.1 (from CRAN), but is fixed in the github version 0.5.2, so I guess I will have to ensure that the people I distribute the report to have the github version, or I have also noticed that if I explicitly call `pander:::pander.aov(m.aov)` then it works, so in my function I could catch things that inherit from `aov` and handle them explicitly if the user does not have pander 0.5.2. – mathematical.coffee Dec 11 '14 at 13:06
  • Voting to close as it's a bug in the current CRAN version pander package that is not present in the github version. – mathematical.coffee Dec 11 '14 at 13:06
  • Thank you @mathematical.coffee, I'll release a minor update on CRAN in a few weeks. – daroczig Dec 11 '14 at 13:15
  • @daroczig, in the current version, the command `pander:::pander.anova` has the same problem, it does not print if calling `pander` only – Zhenglei Mar 30 '15 at 09:36
  • @Zhenglei the current version refers to the CRAN version or the dev (GitHub) version? – daroczig Mar 30 '15 at 17:55
  • @daroczig,the dev version – Zhenglei Mar 30 '15 at 19:40
  • @Zhenglei can you please post here or e.g. on pastebin/gist a reproducible example? It seems to work fine on my machine, but I might miss something. I tried `anova(aov(Sepal.Width ~ Species * Sepal.Length, iris))` based on the above examples. – daroczig Mar 30 '15 at 20:42
  • @daroczig ```{r results='asis'} require(car) require(pander) a <- Anova(aov(Sepal.Width ~ Species * Sepal.Length, iris)) for(i in 1:3) pander(a) ``` – Zhenglei Mar 30 '15 at 22:22
  • @daroczig basically it happened in loops or lapply. If calling `pander:::pander.anova`, the problem disappeared and print out the output as expected. – Zhenglei Mar 30 '15 at 22:24
  • @Zhenglei ah, that's a special case -- as `pander` is not printing to `stdout` since `0.50` and there is no need to specify `results='asis'` (in most cases) for convenience, but if you want the old behaviour, then look for `knitr.auto.asis` [general option](http://rapporter.github.io/pander/#general-options) or in more details check [this blogpost on using `pander` inside of `knitr`](http://blog.rapporter.net/2014/09/pander-tables-inside-of-knitr.html). – daroczig Mar 31 '15 at 07:15

0 Answers0