The compile sequence for a file using LaTeX and R code which is to be processed through knitr is as follows where * is your filename without extension. I would recommend that you run these using TeXworks (bundled with MikTeX) and R before you diagnose the problem in RStudio. RStudio in the past was very picky on setup of supporting programs (I have not used it recently)
- The *.tex file is renamed with the suffix *.Rnw (this is case sensitive)
- Within the now *.Rnw file you need to use R-blocks to load any needed R library's and do any computations.
- When the *.Rnw file is ready for a compile (and you file is ready when renamed) you then need to start R, change the working directory to the same one as the *.Rnw file. Now you need to Load the knitr package. (If needed install it and thereafter just load it.
- In the R console you issue the command
knit *.Rnw
and this will create a *.tex file with the R commands replaces with the output.
- Now return to your LaTeX and run pdflatex twice and then run your viewer.
If you are using an IDE there are setups which allow you to do all of this from within the LaTeX IDE. However I am not familiar with current version of RStudio. In the past it was not able to run knitr from RStudio as then RStudio was hardwired for Sweave.
I would recommend you visit http://yihui.name/knitr/ as the author of knitr has provided an extensive help and demo site(examples).
I think yo' is right with the comment, that the .aux
file is truncated:
\documentclass{article}
\begin{document}
\tableofcontents
\section{Hello World}
\end{document}
After pdflatex test.tex
the .aux
file is:
\relax
\@writefile{toc}{\contentsline {section}{\numberline {1}Hello World}{1}}
Then the .aux
file is edited in an editor to truncate it to:
\relax
\@writefile{toc}{\contentsline {s
Running again:
pdflatex -file-line-error test.tex
gives the error in the same format as in the question:
) (./test.aux)
Runaway argument?
{\contentsline {s
./test.tex:2: File ended while scanning use of \@writefile.
<inserted text>
\par
l.2 \begin{document}
?
The \@writefile
command starts on line 2 in file test.aux
, but the error is detected after the file end, thus the file name is shown as test.tex
.
Back to the question, the error occurs during the first read of the .aux
file. The .aux
file is truncated at line 16.
Suspicion: The file size of the .aux
file is just a sector with 512 bytes. Thus the write cache did not get flushed at the probably abnormal end of the previous LaTeX run.
Deleting the .aux
file and running LaTeX again should fix the issue, when the run is not aborted due to a fatal error.
Best Answer
It suggests that you have at least two code chunks with the same label
match
, like thisDuplicate labels are not allowed in knitr.