I have an .Rnw file that contains the code below. Run knitr::knit()
once and the R code doesn't doesn't echo. Run knitr::knit()
a second time and the R code echoes in the PDF. Why? How can I prevent R code from echoing?
<<load_chapter_2, echo=FALSE, warning=FALSE, message=FALSE,cache=TRUE>>=
options(digits=2)
opts_chunk$set(eval=TRUE, results = "hide", echo=FALSE, warning=FALSE, message=FALSE, fig.height=5, fig.width=5, fig.pos="!ht", fig.align='center')
@
\documentclass[a4paper,11pt]{article}
\usepackage{lipsum} % Required to insert dummy text
% \usepackage{nameref} commented out as was causing extra \else error
\usepackage{graphicx}
\usepackage{placeins} % to control figure placement with \FloatBarrier
\usepackage{xspace}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{array} % for line breaks in table
\usepackage[comma, sort&compress]{natbib}
\setlength{\bibsep}{0pt plus 0.3ex}
\begin{document}
\title{}
\author{}
\date{\today}
\maketitle
\section{Header}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<<plot_1>>=
plot(1)
@
\FloatBarrier
\end{document}
You shouldn't cache your setup block - this means that your
options
andopts_chunk$set
won't be run on subsequent calls ofknit()
.cache = TRUE
should be used for blocks of code that produce results where if the code hasn't changed, the results won't have changed either. However, you also need to be careful of dependencies.See http://yihui.name/knitr/demo/cache/ for more detail. Look in particular at the section labelled 'Important notes' which has the following: