yihui/knitr — Issue #58: A case for chunk reference
Author: ramnathv
Created: 2011-12-15 23:02:29+00:00
State: open

I understand that you have dropped `chunk reference` in knitr. You are right that in most cases, there are easy workarounds by capturing the output of the chunk, either using a variable or a function, and use it later. However, this sometimes leads to verbose documents. Here is an example

```tex
\documentclass[11pt,english,nohyper,noae,xcolor = table]{tufte-handout}
\title{Latex Tables in R: Introduction}
\author{Ramnath Vaidyanathan}

\begin{document}

<>=
suppressMessages(library(Hmisc))
x = head(mtcars)[,1:3]
latex(x, title = "Simple Table", file = "", table.env = F)
@

<>=
latex(x, title = " ", file = "", table.env = F)
@

\begin{margintable}
<>=
latex(x, title = " ", file = "", table.env = F)
@

\caption{Simple Table}
\end{margintable}

\end{document}

```

Note that I am having to write the `latex` chunk so that my code is displayed in the document, while the output is in the margins. I could potentially do `tab <- capture.output(latex(x, title = "", file = "", table.env = F)` and use `tab` in the next chunk, but it feels a little hackish to me.

I know this is a special case, but if there are more situations like this, resurrecting chunk reference, might be useful.