Issue with creating PDf file with Pander+Knitr: Error when putting table with caption and plot directly next to each other

我怕爱的太早我们不能终老 提交于 2019-12-24 05:13:24

问题


I have a reproducible error with pander (+ knitr): When a table with caption and a plot is put directly to each other, I cannot create a PDF File. I use pander 0.5.1, knitr 1.7, R version 3.1.1, Miktex + RStudio on Windows.

So the following will produce the error (see also my List of errors and non-errors below):

```{r, echo=FALSE, eval=TRUE}
pander(cor(cars), caption="Whatever" ) # or some other captioned table

hist(cars$speed) #or some other plot

```

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" Teste_markdown_Cor+Hist.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures
--output Teste_markdown_Cor+Hist.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

When I manually copy&paste the output from pander, the issue seems to be with an empty line before the plot:

Doesnt Work:

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

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

Table: K
```{r, echo=FALSE, eval=FALSE}
hist(cars$speed)
```

Works without Error

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

Table: K

```{r, echo=FALSE, eval=FALSE}
hist(cars$speed)
```

But even if I put different empty lines in the code-chunk between pander and the plot, the error continues

List:

---
title: "Teste Cor + Hist"
output: pdf_document
---
# Does not work

```{r, echo=FALSE}
library(pander)
```

Does not work:
```{r, echo=FALSE, eval=TRUE}
pander(cor(cars), caption="Korrelationen" )
hist(cars$speed)

```

Does not work :
```{r, echo=FALSE, eval=FALSE}
pander(cor(cars), caption="Korrelationen" )
plot(cars)

```

Does not work:
```{r, echo=FALSE, eval=FALSE}
pander(cor(cars), caption="K" )
plot(cars)
```

Does not work:
```{r, echo=FALSE, result='asis', comment=NA,  eval=FALSE}
    pander(cor(cars), caption="Korrelationen" )

 #several line breaks


hist(cars$speed)

```    

Doesnt Work: 

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

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

Table: K
```{r, echo=FALSE, eval=FALSE}
hist(cars$speed)
```

# Works without Error
--------------------------
        speed   dist 
----------- ------- ------
 **speed**     1    0.8069  
 **dist**   0.8069    1   
--------------------------

Table: K

```{r, echo=FALSE, eval=FALSE}
    hist(cars$speed)
    ```



Works:
```{r, echo=FALSE, eval=TRUE}
cat("Korrelationen")
hist(cars$speed)

```

Works:
```{r, echo=FALSE, eval=TRUE}
pander(cor(cars), caption="Korrelationen" )
cat("Korrelationen")
hist(cars$speed)

```

Works:
```{r, echo=FALSE, eval=TRUE}
cat("table: Korrelationen")
hist(cars$speed)

```

Works:
```{r, echo=FALSE, result='asis', comment=NA,  eval=TRUE}
pander(cor(cars), caption="Korrelationen" )
cat("table: Korrelationen")
hist(cars$speed)

```

回答1:


I found a workaround manualy adding a lineabreak at the end of the caption. But I still think this should be considered a bug?!?

Works:
```{r, echo=FALSE, eval=TRUE}
pander(cor(cars), caption="whatever text\n" )
hist(cars$speed)

```


来源:https://stackoverflow.com/questions/26861074/issue-with-creating-pdf-file-with-panderknitr-error-when-putting-table-with-ca

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