1

It seems like the \only command cannot be used to show a R chunk. Here is a MWE producing the error:

\documentclass[11pt]{beamer}
\usetheme{Warsaw}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}

<<setup, include=FALSE>>=
library(knitr)
@

\title{Title}

\begin{document}
\section{Section name}
\begin{frame}[fragile]
\frametitle{\insertsection}

Add \verb!\only<1>{ ... }! around the code chunk to produce crash
<<>>=
2+2
@

\end{frame}

\end{document}

I got this error message

Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, : Running 'texi2dvi' on 'KnitrOnly.tex' failed. LaTeX errors: ! Paragraph ended before \@xverbatim was complete. <to be read again> \par l.16 } ! LaTeX Error: \begin{kframe} on input line 16 ended by \end{beamer@framepauses }. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ! Missing } inserted. <inserted text> } l.85 \end{frame}

! Extra }, or forgotten \endgroup. \endbeamer@frameslide ...amer@framepauses}\egroup \ifx \beamer@frametitle \@... l.85 \end{frame} ! LaTeX Error: \begin{knitrout} on input line 16 ended by \end{beamer@frameslid e}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ! LaTeX Error: \begin{beamer@framepauses} on input line 85 ended by \end{docume nt}. See the LaTeX manual or LaTeX Companion
1

It works with \onslide<>, see the figure.

\onslide<2->
<<>>=
2+2
@
\onslide<3>
<<>>=
3+3
@

Example for \onslide<> working in knitr

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – CarLaTeX Sep 9 '17 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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