1

I am trying to create a long document in R Studio using R Markdown to PDF, and I am getting the following error when I push the "Knit PDF" button:

! Undefined control sequence.
l.124 \begin{center}\includegraphics

pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Execution halted

I am able to properly create the PDF if I make a new R Markdown document and I paste the code in from the original, provided I keep the following code at the end of the new document. When I erase this code, I get the above error.

```{r, echo=FALSE}
plot(cars)
```

I have no need or desire for the cars plot to be in my document. I am able to Knit this document into HTML without the undesired code, but not to PDF. Can anyone advise why this error may be happening? (This is my first post to this forum, so if you need more specific information, please advise).

I am running Windows 7 32 bit, R Studio version 0.98.1103, MiKTeX version 2.9.

Edit/Update: Here is my code, including the cars graph which I do not want.

---
title: "Untitled"
date: "Saturday, April 25, 2015"
output: pdf_document
---
```{r echo=FALSE, warning=FALSE, include=FALSE}
   require(qcc)
   require(data.table)
   require(ggplot2)
   require(sm)
   require(knitr)
   require(xtable)
   attach(airquality)
   airquality$indicator <- ifelse(airquality$Month < 8,'Classic','New')

```

```{r echo=FALSE, warning=FALSE, results='hide', fig.align='center'}
    par(mfrow=c(2,1), oma=c(1,1,1,1), cex=.5, mex=.5, ps=8, mgp=c(3,1,0))    
    airquality <- airquality[complete.cases(airquality),]

    # Plot variable on an SPC chart of type xbar.one
    imrchart2 <- qcc(airquality$Ozone[airquality$indicator=="Classic"], "xbar.one", std.dev="SD", add.stats=TRUE, ylab="Ozone", title="Xbar.One Chart for Ozone", xlab="", data.name="Classic", restore.par=FALSE, newdata=airquality$Ozone[airquality$indicator=="New"], newdata.name="New", ylim=range(airquality$Ozone))
    # Plot a CUSUM chart 
    cusum(airquality$Ozone[airquality$indicator=="Classic"], sizes=1, add.stats=TRUE, ylab="Ozone", title="CUSUM Chart for Ozone", xlab="", restore.par=FALSE, newdata=airquality$Ozone[airquality$indicator=="New"], data.name="Classic", newdata.name="New")
```

```{r, echo=FALSE}
plot(cars)
```
CoachR
  • 11
  • 2
  • It's basically impossible to help with this without being able to reproduce the error. Try to find a minimal excerpt of your original document that reproduces the error, and post that – arvi1000 Apr 25 '15 at 17:12
  • arvi1000 - updated with code, please let me know if this is something you have advice on. thx in advance. – CoachR Apr 25 '15 at 21:45
  • I'm wondering if plot.new() has the same effect as plot(cars). This may or may not insert a blank figure in your pdf, so it might not be a great solution. (Sorry I don't have time to test it now, but it might be a step in the right direction...). Also calling `par(mfcol=c(1,1))` might have a similar effect. – Jthorpe Apr 26 '15 at 00:56
  • @Jthorpe `plot.new()` worked, but `par(mfcol=c(1,1))` did not. I tried removing my original par statement, but this produced the same error. I would still like to understand if there is a better way around this error than `plot.new()`, but thank you very much for the help. – CoachR Apr 26 '15 at 03:10
  • [This question](http://stackoverflow.com/questions/25856362/pandoc-document-conversion-failed-with-error-43-pdflatex-the-memory-dump-file) suggests `fig.align='center'` causes the problem, and it seems it has to do with encoding. Try removing the option or adding `latex_engine: xelatex` in your preamble – scoa Apr 26 '15 at 12:33
  • @scoa - that was the fix! Removed fig.align from the file and it is working properly. Thanks! – CoachR Apr 27 '15 at 14:49

0 Answers0