Pander + Knitr的问题:使用pander.list时出错 [英] Issue with Pander+Knitr: Error when using pander.list
问题描述
pander(+ knitr)另一个可重现的错误:当我尝试平移列表时,无法创建PDF文件-当表或data.frame放在列表中时,似乎会发生这种情况.如果列表中仅包含向量,则PDF可以编译,但外观很难看.
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.
我在Windows上使用pander 0.5.1,knitr 1.7,R版本3.1.1,Miktex + RStudio.
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) ) )
```
错误:
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
当我在控制台中使用pander并手动复制并粘贴它时,它将进行编译:
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 ) )
```
如果我将Vectors放入列表中,它可以工作,但是输出也很难看,因为属性也被解析了:
{r}
pander(list(a=c(1,2,3),b=c('A','b') ) )
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输出:
• 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
推荐答案
我找到了一种解决方法,在pander中禁用了knitr.auto.asis选项,并在knitr中手动设置了result ='asis'.但我仍然认为应该将其视为错误?!?
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) ) )
```
这篇关于Pander + Knitr的问题:使用pander.list时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!