Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I hope this is in the right place. For my statistics assignments, I do the computation inline with Sweave, like so:

\begin{itemize}
 \item[Problem 1]
  <<label=block1,eval=T,echo=F>>
   varA <- 2+2
  @

  The answer to the problem is \Sexpr{varA}
\end{itemize}

I'd like to be able to reproduce the code in full in an appendix, but this doesn't work:

\subsection*{Code}
 <<block1>>
 @

There must be a clean way to do this that I'm missing.

share|improve this question
    
Are you missing an = after the last`>`? –  Roman Luštrik Apr 30 '12 at 7:00
add comment

2 Answers

up vote 3 down vote accepted
  1. as R. Schumacher mentioned, <<>>= and @ must start on the first column;
  2. <<>> is supposed to be used within a code chunk, so you have to put it under <<>>=;

Here is a complete example:

\begin{itemize}
 \item[Problem 1]
<<block1,eval=T,echo=F>>=
 varA <- 2+2
@

  The answer to the problem is \Sexpr{varA}
\end{itemize}

\subsection*{Code}

<<all-blocks>>=
<<block1>>
@
share|improve this answer
    
Ah, I didn't know I had to include <<block1>> in another block. Thanks! –  Patrick McCarthy Apr 30 '12 at 21:39
add comment

The <<>>= and @ must start on the first column and nothing follows on the same line.

The file must be saved as yourfilename.Rnw, then run Sweave(yourfilename.Rnw) which will give you yourfilename.tex which now can be compiled with LaTeX. Recommend that you put yourfilename.Rnw in a folder where only this project is done.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.