# Comparing reproducible research strategies: brew or Sweave vs. R2HTML

This is a bit more "think about it" question - but I see it as an important one to ask.

I have been struggling for the past few days with having a more reproducible-research-like workflow. I am confused with the two different strategies for writing a report.

The two strategies are:

1. Sweave or brew. Where there is a report.Rnw or report.brew file that has a mixture of some markup language (either HTML or LaTeX) and R code between special braces (say <<>>= @). This file needs to be run through Sweave or brew in order to create the report file (report.html or report.tex).
2. R2HTML (for HTML) and Hmisc (for LaTeX). Where the .r file uses R functions to construct report.html or report.tex; running the R commands generates the report directly.

What is clear to me is that most people online seem to be using option 1. But I do not understand why it is so common, when option 2 seems to me (without too much experimenting) to be less work.

When is each of the two strategies better?

Any ideas/feedback/thoughts would be welcome, Thanks.

-
Based on your comment below, I'd suggest editing the question to take out your struggles with LaTeX, as that makes it feel like it's an HTML vs LaTeX question, and mentioning the Hmisc library in method 2 as a way of doing a similar thing but with LaTeX. –  Aaron Sep 22 '11 at 2:16
Hi Aaron, I'll edit it a bit... –  Tal Galili Sep 22 '11 at 21:39
Thanks for your edit. I took the liberty of editing it further to make it clearer what Hmisc does (and some other smaller edits); if it makes it past peer review, you can decide if it still reflects your question accurately. –  Aaron Sep 23 '11 at 14:41
Good editing Aaron - thanks! –  Tal Galili Sep 25 '11 at 21:21
Just wanted to add org-mode with Babel as another way of achieving something sweave-like without the need to dig to deep into latex (or to use it as the starting point for finer latex tuning). Available in emacs. –  Henrik Sep 27 '11 at 20:53

New answer based on comment below:

As I understand, Method 1 is to mix R code and HTML or LaTeX in the same document, using Sweave or brew for example, to create a final document, while Method 2 is to use R code to generate HTML or LaTeX, using the R2HTML or Hmisc packages for example, and then to just run the R code to create the final document. I've mostly just used Method 1 but will weigh in anyway.

As I see it, it's really just a matter of preference; I don't see any technical or statistical reason to prefer one over the other; they're both ways to make your research reproducible.

I think Method 1 is easier because you don't have to know what the R functions are that create the LaTeX or the HTML code; you just write R code, and you write HTML or LaTeX code, and the software takes care of putting them together. This is especially true when the R output only is a small amount of the final document; it would be a pain to write the R code necessary to output a lot of text, for example. In smart text editors, you also get the right syntax formatting for each kind of code which you don't get when using R2HTML or Hmisc. This method also separates the results from the commentary more cleanly, in my opinion.

However, for short snippets or just outputting the results from a command with no commentary, using R2HTML or Hmisc might be easier, though (speaking from my experience), once you're in the habit of Sweaving, you'll never go back.

-
Thank you for the response Aaron. Notice though that the question is not between HTML and LaTeX, but between writing the report and having the R code in it Versus writing R code that also include code for constructing the report. Maybe I should come up with an example to illustrate - but thanks for taking the time to answer... –  Tal Galili Sep 21 '11 at 20:39
Looks like both Aaron and I had the same reading of your question. I'd consider an example to illustrate, and hopefully we can be more helpful. –  EpiGrad Sep 21 '11 at 21:30
@TalGalili: edited based on your comment; also, consider putting this in the question, see my comment to the question for details. –  Aaron Sep 22 '11 at 2:34
Aaron - thank you for the updated answer. I generally agree with your answer. I'll need to think more about the Sweaving... –  Tal Galili Sep 22 '11 at 7:37

These are just a few points.

• If you want to just write simple reports, then the set of LaTeX commands that you need to learn is a lot smaller than if you want to do complex things.
• An appealing aspect of LaTeX over some simple markup systems is that if you want features like referencing, automatic numbering, multi-page tables, attractive type setting, these features are available. In particular, there have been features that initially I hadn't even thought of, but when I have needed them, they have been available in LaTeX as a package.
• If you want your final report in a different format, such as HTML or rtf, then you can use various conversion programs like pandoc to convert the latex into that format.
-
Point 1 is reassuring :) –  Tal Galili Sep 22 '11 at 10:19

The other nicE thing potentially about LaTeX or another markup in the Sweave/odfWeave/asciiWeave paradigm is that for repeated reports you can template it a bit better once and then just reuse the template. See Harrell's rreport package as an example

-