6
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Commented Sep 22, 2011 at 2:16
  • $\begingroup$ Hi Aaron, I'll edit it a bit... $\endgroup$
    – Tal Galili
    Commented Sep 22, 2011 at 21:39
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Sep 23, 2011 at 14:41
  • $\begingroup$ 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. $\endgroup$
    – Henrik
    Commented Sep 27, 2011 at 20:53

5 Answers 5

8
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ 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... $\endgroup$
    – Tal Galili
    Commented Sep 21, 2011 at 20:39
  • $\begingroup$ 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. $\endgroup$
    – Fomite
    Commented Sep 21, 2011 at 21:30
  • $\begingroup$ @TalGalili: edited based on your comment; also, consider putting this in the question, see my comment to the question for details. $\endgroup$ Commented Sep 22, 2011 at 2:34
  • $\begingroup$ Aaron - thank you for the updated answer. I generally agree with your answer. I'll need to think more about the Sweaving... $\endgroup$
    – Tal Galili
    Commented Sep 22, 2011 at 7:37
6
$\begingroup$

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.
$\endgroup$
1
  • $\begingroup$ Point 1 is reassuring :) $\endgroup$
    – Tal Galili
    Commented Sep 22, 2011 at 10:19
3
$\begingroup$

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

$\endgroup$
2
$\begingroup$

You're pretty safe in using either - though I confess I don't use either at all. I suspect the primary reason for the popularity of the LaTeX/Sweave method is the number of fields that use LaTeX as their primary paper/presentation/manuscript format that incentivizes using a LaTeX based system. I don't know of a single field where a .html end product is all that directly useful.

$\endgroup$
3
  • $\begingroup$ dunno about the popularity of latex due to field requirements. I work in a field (psychology) where almost nowhere takes tex, and i still use it (to avoid drawing tables and formatting manually). I think its popularity has more to do with its age rather than anything else. $\endgroup$ Commented Sep 22, 2011 at 12:25
  • $\begingroup$ @richiemorrisroe There are certainly some people who use it for whatever reason - they like it, they dislike manual formatting, whatever. I have however found, hopping between fields, that I run into fields that almost never use LaTeX (my own) and fields where it was once asserted "If its going to be published, it must be in LaTex". That conversation ended in me having to go print out a copy of AJE's submission guidelines. $\endgroup$
    – Fomite
    Commented Sep 22, 2011 at 17:55
  • 1
    $\begingroup$ i sometimes wish i worked in one of the LaTeX heavy fields, it would save me a lot of time and hassle throughout my doctorate. $\endgroup$ Commented Sep 22, 2011 at 18:53
1
$\begingroup$

The reason option 1 is so common is because...it is so common. Sweave has been around for the better part of 10 years and, for many R users, is synonymous with reproducible research. Furthermore, the sorts of people who would hear the phrase 'reproducible research' and think 'that sounds great' are probably likely to already be familiar with LaTeX. Thus, it is not as if they are picking between two options because many won't know that option 2 even exists.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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