[R] Sweave, beamer and alert within code chunks

Yihui Xie xie at yihui.name
Thu May 10 00:54:00 CEST 2012


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 <xieyihui at gmail.com>
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 <gpetris at uark.edu> 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  <GPetris at uark.edu>
> Associate Professor
> Department of Mathematical Sciences
> University of Arkansas - Fayetteville, AR 72701
> Ph: (479) 575-6324, 575-8630 (fax)
> http://definetti.uark.edu/~gpetris/
>



More information about the R-help mailing list