Search code examples
rpdfknitrtinytex

"Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%3d.pdf, " when I compile PDF in RStudio (KNITR package)


I created a Sweave file in RStudio, with mostly code:

\documentclass{article}
\begin{document}

Hello

<<>>=
library(x)   
library(y)
library(z)
data(dataset)
plot(dataset$variable1, dataset$variable2)
[...] #This means "other lines", not literally written in my file
@

\end{document}

The PDF compilation went fine. Then I added more lines of code, but when I recompiled I got the error:

Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%3d.pdf,

In the Issues tab, it said the problem lies in opening the image file it created when I compiled the PDF for the first time. Any advice?


Solution

  • SOLVED:

    I deleted all the files created with the compilation in the folder which contains my .Rnw file, except for the .Rnw file: I deleted the "figure" folder (which contained only the graph), the .log file, the .tex files, the .pdf file, and the .gz file. Then I compiled the PDF again, it worked.