I am using the knitr-package (version 1.10.5) to produce latex beamer slides. The per cent symbol in the matrix multiplication operator %*% is interpreted as a LaTeX comment.
The knitr chunk looks the following
\begin{frame}
<<echo=TRUE,eval=TRUE>>=
x<-1:10
y<-1:10
x%*%y
@
\end{frame}
and this is the LaTeX code I get
\begin{frame}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{x}\hlkwb{<-}\hlnum{1}\hlopt{:}\hlnum{10}
\hlstd{y}\hlkwb{<-}\hlnum{1}\hlopt{:}\hlnum{10}
\hlstd{x}\hlopt{%*%}\hlstd{y}
\end{alltt}
\begin{verbatim}
## [,1]
## [1,] 385
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
I found the solution. The amendment [fragile] helps a lot:
\begin{frame}[fragile]
<<echo=TRUE,eval=TRUE>>=
x<-1:10
y<-1:10
x%*%y
@
\end{frame}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.