environment undefined error

798 views
Skip to first unread message

Ross Ahmed

unread,
Jan 2, 2014, 1:46:33 PM1/2/14
to kn...@googlegroups.com
I am using knitr to convert an .Rnw file into a .tex file. The .tex file outputted by knitr is part of several .tex file that are being combined together to produce a .pdf. 

When I run knit(), this is the code in the output .tex file:


\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}


{\ttfamily\noindent\color{warningcolor}{\#\# Warning: Removed 3 rows containing missing values (geom\_path).}}\end{kframe}
\includegraphics[width=\maxwidth]{figure/my_plot} 

\end{knitrout}


When I try to convert the output .tex file into a .pdf, I am getting these errors:

Latex Error: ./Chapters/Chapter2.tex:121 LaTeX Error: Environment knitrout undefined.

Latex Error: ./Chapters/Chapter2.tex:122 LaTeX Error: Undefined color `fgcolor'.

Latex Error: ./Chapters/Chapter2.tex:122 LaTeX Error: Environment kframe undefined.

Latex Error: ./Chapters/Chapter2.tex:125 LaTeX Error: Undefined color `warningcolor'.

Latex Error: ./Chapters/Chapter2.tex:125 LaTeX Error: \begin{document} ended by \end{kframe}.

Latex Error: ./Chapters/Chapter2.tex:126 LaTeX Error: File `figure/my_plot' not found.

Latex Error: ./Chapters/Chapter2.tex:128 LaTeX Error: \begin{document} ended by \end{knitrout}.


Does anyone know why I am getting these errors and how to solve the problem?

Yihui Xie

unread,
Jan 5, 2014, 1:19:58 AM1/5/14
to Ross Ahmed, knitr
My guess is Chapter2.Rnw does not have the LaTeX preamble starting
with \documentclass{}. It is not a complete LaTeX document, so you
should not compile it on its own. Or you have to run knit() on the
main Rnw document to generate the required preamble.

Suppose this is the structure of your project:

main.Rnw
- Chapter1.Rnw
- Chapter2.Rnw

In main.Rnw, you should

<<chap1, child="Chapter1.Rnw">>=
@

Then knit('main.Rnw'). You do not need to knit the chapters individually.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
Reply all
Reply to author
Forward
0 new messages