Sweave, beamer and alert within code chunks

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Sweave, beamer and alert within code chunks

Giovanni Petris

Hi all,

Using Beamer, in order to highlight a piece of R code I do something
like this - note the "\structure" and "\alert" commands:

\begin{semiverbatim}
> mleOut <- \structure{dlmMLE}(Nile,
+                  parm = c(0.2, 120), # initial values for optimizer
+                  lower = c(1e-7, 0)) \alert<2>{# V must be positive}
> mleOut$convergence  \alert<3>{# always check this!!!}
[1] 0
\end{semiverbatim}

How can I get a similar effect using Sweave?

Thank you in advance!

Best,
Giovanni Petris


--

Giovanni Petris  <[hidden email]>
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Sweave, beamer and alert within code chunks

Yihui Xie-2
Syntax highlighting is easy with the highlight package, on which the
knitr package is based, e.g.

- sample source: https://gist.github.com/1803930
- sample pdf: https://github.com/downloads/yihui/knitr/knitr-beamer.pdf

It is possible to insert \alert{} with knitr, but you have to provide
the logic: where do you want to insert them? use \alert{} on all
comments?

Anyway, here is a demo:

- source: https://gist.github.com/2629886#file_knitr_alert.rnw
- output: https://github.com/downloads/yihui/knitr/knitr-alert.pdf

The knitr hooks allows you to wrestle with R code and output in any
way you want, and you may need one hour or two learning the design.

BTW, I'm not sure if it is my problem or yours -- your code does not
actually run under my R 2.15.0. Long live the reproducible research!

Regards,
Yihui
--
Yihui Xie <[hidden email]>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Wed, May 9, 2012 at 4:13 PM, Giovanni Petris <[hidden email]> wrote:

>
> Hi all,
>
> Using Beamer, in order to highlight a piece of R code I do something
> like this - note the "\structure" and "\alert" commands:
>
> \begin{semiverbatim}
>> mleOut <- \structure{dlmMLE}(Nile,
> +                  parm = c(0.2, 120), # initial values for optimizer
> +                  lower = c(1e-7, 0)) \alert<2>{# V must be positive}
>> mleOut$convergence  \alert<3>{# always check this!!!}
> [1] 0
> \end{semiverbatim}
>
> How can I get a similar effect using Sweave?
>
> Thank you in advance!
>
> Best,
> Giovanni Petris
>
>
> --
>
> Giovanni Petris  <[hidden email]>
> Associate Professor
> Department of Mathematical Sciences
> University of Arkansas - Fayetteville, AR 72701
> Ph: (479) 575-6324, 575-8630 (fax)
> http://definetti.uark.edu/~gpetris/
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.