Issue with Pander+Knitr: Error when using pander.list

不羁的心 提交于 2019-12-19 07:48:52

问题


Another reproducible error with pander (+ knitr): When I try to pander a list, I cannot create a PDF File - it seems to occur when a table or data.frame is put inside the list. If only vectors are in the list, the PDF compiles but looks ugly.

I use pander 0.5.1, knitr 1.7, R version 3.1.1, Miktex + RStudio on Windows.

Doesn't work:
```{r, eval=FALSE}
pander(list(cor=cor(cars) ) )
```

Error:

output file: Preview-e905ccd5f1a.knit.md

! Undefined control sequence.
l.246   \textbf{cars}: {[}1{]} ``\n

pandoc.exe: Error producing PDF from TeX source
Fehler: pandoc document conversion failed with error 43
Zus�tzlich: Warnmeldung:
Ausf�hrung von Kommando '"C:/Program Files/RStudio/bin/pandoc/pandoc" Preview-e905ccd5f1a.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output Preview-e905ccd5f1a.pdf --template "C:\Users\jbothe\Documents\R\win-library\3.1\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' ergab Status 43 
Ausf�hrung angehalten

It compiles when I use pander in the console and manually copy and paste it:

* **cor**:

    --------------------------
            speed   dist
    ----------- ------- ------
     **speed**     1    0.8069

     **dist**   0.8069    1
    --------------------------

The same error occurs when trying to put cars in the list:

```{r, eval=TRUE}
pander(list(cars=cars ) )
```

If I put Vectors into the list, it works, but the output looks ugly, since attributes are parsed as well: {r} pander(list(a=c(1,2,3),b=c('A','b') ) )

PDF-Output:

• a: [1] “1, 2 and 3” attr(,“class”) [1] “knit_asis” attr(,“knit_cacheable”) [1] TRUE
• b: [1] “A and b” attr(,“class”) [1] “knit_asis” attr(,“knit_cacheable”) [1] TRUE

回答1:


I found a workaround, disabling the knitr.auto.asis option in pander and manually setting results='asis' in knitr. But I still think this should be considered a bug?!?

## Workaround with asis
```{r results='asis'}
panderOptions('knitr.auto.asis', FALSE)
pander(list(a=c(1,2,3),b=c('A','b')  ) ) 
```

```{r, results='asis'}
panderOptions('knitr.auto.asis', FALSE)
pander(list(cor=cor(cars) ) )
```


来源:https://stackoverflow.com/questions/26863406/issue-with-panderknitr-error-when-using-pander-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!