Knitr: Display tilde ~ in beam overlay

This may be a boundary case, but I'm trying to create a ray presentation with knitr where I want to display a piece of code using different formulas as arguments for a function. I found that when using overlays, the tilde in code snippets disappears. Is there a way to get them to display?

Here's a minimal reproducible example:

\documentclass{beamer}
\begin{document}


\begin{frame}[fragile]
\frametitle{Slide with overlay}
\only<1>{
<<notilde, eval = FALSE>>=
myfunction(data, formula = ~ x)
@
}
\only<2>{
<<notilde2, eval = FALSE>>=
myfunction(data, formula = y ~ x)
@
}
\end{frame}

\begin{frame}[fragile]
\frametitle{Slide without overlay}
<<tilde, eval = FALSE>>=
myfunction(data, formula = ~ x)
@
\end{frame}

\end{document}

The first frame of the presentation is as follows:

slide with overlay

Any help is appreciated.

EDIT:

An overlay slide looks like this:

slide without overlay

To clarify the syntax <<...>>and @is specific for the R-pack package. Anything between these characters is interpreted by knitr as fragments of R code and converted to latex to enable syntax highlighting.

+4
1

~ $\ sim $

, , , , .

: ? : & ​​lt; <... → =... @ ? , highlihting.

+1

All Articles