2

我对 pander (+ knitr) 有一个可重现的错误:当带有标题的表格和绘图直接相互放置时,我无法创建 PDF 文件。我在 Windows 上使用 pander 0.5.1、knitr 1.7、R 版本 3.1.1、Miktex + RStudio。

因此以下将产生错误(另请参阅下面的错误和非错误列表):

```{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

当我手动复制和粘贴 pander 的输出时,问题似乎出在绘图前有一个空行:

不工作:

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

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

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

正常工作

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

Table: K

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

但即使我在 pander 和 plot 之间的代码块中放置了不同的空行,错误仍然存​​在

列表:

---
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)

```
4

1 回答 1

1

我找到了一种解决方法,在标题末尾手动添加换行符。但我仍然认为这应该被认为是一个错误?!?

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

```
于 2014-11-11T09:58:52.070 回答