9
$\begingroup$

I am very interested in learning how to create reoccurring reports from my R code and ggplot2 visualization.

I understand that LaTeX seems to be a possible answer, and to use it with R most use Sweave. And for presentations from R to LaTeX people use Beamer.

My question is, what I should learn first, or what should I learn concurrently? I don't know Sweave or LaTeX. Should I learn LaTeX (at least a bit), then learn Sweave? Or would you suggest learning them at the same time?

Links to tutorials supporting your answers greatly appreciated.

$\endgroup$
13
$\begingroup$

Personally I would start here:

http://en.wikibooks.org/wiki/LaTeX

That will teach you how to make a document in LaTeX that compiles. Once you've done that I would just start working with Sweave, and learn about figures, graphics, tables etc. as you go depending on what your needs are (the link above and the marvellous StackExchange (LaTeX/ Cross Validated, Stack Overflow) should keep you going with all that).

Note also that personally I like to have Brew:

http://cran.r-project.org/web/packages/brew/brew.pdf

in my back pocket as well because it's easier for big loopy bits of code where you want to make 50 million graphs or something like that.

Note finally that I was reading about knitr the other day:

http://yihui.name/knitr/

Which apparently plays nicely with ggplot2. It's pretty similar to Sweave, I will check it out some time myself, haven't got round to it yet.

RStudio:

http://rstudio.org/

Is an absolute delight to use both with Sweave and LaTeX documents and a brilliant IDE to boot if you don't already use that.

$\endgroup$
  • 2
    $\begingroup$ The development version of RStudio (0.96) now also support knitr as a weaving engine, so you can easily switch between Sweave and knitr. $\endgroup$ – Antoine Vernet Feb 15 '12 at 14:14
8
$\begingroup$

A Relevant Question

As a complement to the excellent answers above, I would also ask:

Do you really want to learn to use Beamer?

The package has a learning curve - perhaps more than any other slide package for LaTeX - so it's worth checking the pros and cons. For me these are...

Pros:

  1. Almost everybody seems to use it (but does everyone share their source with you? If not, then visual conformity is the only advantage)
  2. Signals that you know LaTeX and will probably have math in your slides, which may have some cachet. [This is not meant ironically; sometimes it is helpful]

Cons:

  1. It's easy to make an article into a talk and vice versa by cut and pasting.
  2. You fit a very large amount of text and math on a slide with the defaults.
  3. Code snippets can be awkward to escape properly.
  4. The built in styles almost all encourage large amounts of boilerplate visuals: sequence in slide set, etc.

Things you could argue either way:

  1. There is a pause command for building up slides line by line (Do you like this? I don't)
  2. Templates are difficult to change so you mostly end up with the built-in ones

For these reasons I've always decided against. For me, visually more pleasing and much simpler options include Foiltex or [gasp] LaTeX's own built in slides class.

Relevance to the Original Question

The relevance of these considerations to the original question is the following: With the tools mentioned above, once one knows how to write the most basic latex document and include pictures in it, there is nothing more to know to be able to make slides.

Not only does this leaves more time for debugging Sweave, which you'll do a lot of, but also frees up time to figure out things like xtable, apsrtable and/or the mtable function in memisc that will turn R model objects to nice LaTeX. These are all worth figuring out before wrestling with a slides package because they are more generally useful.

$\endgroup$
  • $\begingroup$ Very good point. It's never been clear to me why so many people complain about "death by Powerpoint" but no one seems to complain about "death by Beamer". Beamer has all the mind-numbing properties of Powerpoint, and then some. $\endgroup$ – Carlos Accioly Feb 22 '12 at 14:16
  • $\begingroup$ @CarlosAccioly I actually have commented about "death by Beamer" - it's a welcome change of pace in talks dominated by PowerPoint, but after the 50th generic Beamer presentation, it's hard not to tune out. $\endgroup$ – Fomite Feb 26 '12 at 7:57
8
$\begingroup$

Although this is not exactly what you have asked for I recommend you have a look at org-mode, an emacs mode incorporating all your needs.

Why do I recommend org-mode? (i.e., the pros)

  • org-mode allows you to write text and code within one document, with emphasizing both parts equally, text and code (although I have never used sweave I feel the focus is more on code). To this end, org-mode allows for a lot of simplifications when writing text compared to pure LaTeX (i.e., & is & instead of \&, text becomes italic by surrounding it with /, or bold with *). These markup elements will be exported to real LaTeX but make life a lot easier.
  • org-mode allows you to export your text not only as LaTeX or beamer but even html or other formats (e.g., TaskJuggler, ...)
  • org-mode can be used for other tasks suchs as organizing ones life using gtd.
  • Emacs is one of the most popular and mature text editors, available for all platforms, and productively being used since the late 70 for programming tasks of all sorts. Additionally, there exists a very popular connection to R, ESS, developed by, inter alia, R core members Kurt Hornik and Martin Maechler. When using emacs you can use it for all tasks, not only sweave and R integration (that is one reason why some people refer to Emacs as an operating system rather than an editor). Sidenote: Emacs was initialy developed by GNU mastermind Richard Stallman.

The cons:

  • instead of only learning one thing at a time, you will have to learn even more things all at once: Emacs (which arguably has a complicated handling), org-mode and LaTeX.
  • installing Emacs, org-mode, ESS can be a hassle. Especially if you (as I) know nothing about lisp, writing your .emacs file really sucks.

If you want to give it a try (I highly recommend it), there is a very recent paper on org-mode in the Journal of Statistical Software that should get you started.

What I recommend to get started is to first try to do your first documents in org-mode and export them as LaTeX or pdfs (i.e., without R). When succesful, simply try to add some R code to the document and see how you can export the relevant stuff.

I highly recommend obtaining the cheat sheets or reference cards for all of the used programs (Emacs, org-mode, LaTeX, TeX and ESS). Furthermore, a basic understanding of LaTeX as pointed at by Chris Beely (wikibooks) definitely helps a lot, too.

My current setup is that I usually work with three buffers in parallel. One org-mode buffer with the document, one ESS mode R script to keep code and try out different things, and one R console being accessible from both scripts. This works really great.

Some stuff that I like to use:

$\endgroup$
  • $\begingroup$ you make a compelling case for EMACS, but I've already gone deep down the road of learning VIM and am hesitant to traverse that learning curve again. I use the R-Vim-Plugin which is helpful, but doesn't do nearly everything you describe that ESS can do. $\endgroup$ – Idr Feb 24 '12 at 23:04
  • $\begingroup$ I definitely understand, but it seems not to late to start with something new. I am really happy with my current setup. I write papers and do complicated analysis jobs within the same environment. $\endgroup$ – Henrik Feb 25 '12 at 12:01
3
$\begingroup$

You should definitely learn some LaTeX before starting on beamer.

How much LaTeX you want to learn before adding Sweave (or while learning Sweave) depends on what you will do with LaTeX other than write things from R code. LaTeX is huge.

$\endgroup$

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