使用Pander + Knitr创建PDf文件时出现问题:将带有标题的表格和绘图直接放在彼此旁边时出错

时间:2014-11-11 09:02:54

标签: r knitr pander

我有一个可重复的错误与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)

```

1 个答案:

答案 0 :(得分:1)

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

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

```