I am trying to output the source of a knitr block to a beam slider.
For example, I would like the following code snippet to appear as in .Rnw:
<<code-chunk, echo=TRUE, tidy=TRUE>>= @
I tried to recreate this behavior using:
<<out-first-code-chunk, echo=FALSE, comment=NA>>= cat(paste("<<example-code-chunk, echo=TRUE, tidy=TRUE>>=","@",sep="\n")) @
This code is legal since the cat command in the R console gives:
> cat('<<example-code-chunk, echo=TRUE, tidy=TRUE>>=','@',sep='\n') <<code-chunk, echo=TRUE, tidy=TRUE>>= @
However, the resulting latex:
\begin{frame} \frametitle{Code Chunk} To incorporate R code into your knitr documents \begin{knitrout} \definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe} \begin{verbatim} <<example-code-chunk, echo=TRUE, tidy=TRUE>>= @ \end{verbatim} \end{kframe} \end{knitrout}
It produces errors:
<<example-code-chunk, echo=TRUE, tidy=TRUE>>= @ \end {verbatim} \end \ETC. ! Paragraph ended before \@xverbatim was complete. <to be read again> \par l.198 \end{frame} I suspect you've forgotten a `}', causing me to apply this control sequence to too much text. How can we recover? My plan is to forget the whole thing and hope for the best. ! LaTeX Error: \begin{verbatim} on input line 198 ended by \end{ beamer@framepau ses}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.198 \end{frame} Your command was ignored. Type I <command> <return> to replace it with another command, or <return> to continue without it. ! LaTeX Error: \begin{kframe} on input line 198 ended by \end{ beamer@frameslide }.
Why does latex medium think it's literally not closed? Is there a more suitable way to display the piece code as a whole?