[Tex/LaTex] display \Sexpr{} in Latex without evaluation

knitr

I am working on a tutorial for the knitr package using the beamer class. I was able to display latex code and knitr chunks inside my presentation without evaluation but I additionally want to add inline code, namely \Sexpr{} without evaluation. So the three dots (…) should be replaced by \Sexpr{pi}. Any suggestions?

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{listings}
\lstset
{
language=[LaTeX]TeX,
breaklines=true,
basicstyle=\tt\scriptsize,
keywordstyle=\color{blue},
identifierstyle=\color{black},
}
\usepackage[utf8]{inputenc}
\usetheme{Madrid}

\title{}

\begin{document}

<<setup,echo=FALSE,include=FALSE>>=
render_listings()
@


\begin{frame}[fragile]{}{}

\begin{lstlisting}
\documentclass{article}
\begin{document}
The value of $\pi$ is ...


\Sexpr{''}<<label>>=
print("knitr!")
@

\end{document}
\end{lstlisting}



\end{frame}

\end{document}

Best Answer

You can use escapechar:

\begin{lstlisting}[escapechar=|]
\documentclass{article}
\begin{document}
The value of $\pi$ is \Sex||pr{pi}


||<<label>>=
print("knitr!")
@

\end{document}
\end{lstlisting}