Differences between revisions 4 and 5
Revision 4 as of 2013-04-17 16:55:57
Size: 1496
Editor: wifi
Comment:
Revision 5 as of 2013-04-17 17:09:42
Size: 2800
Editor: wifi
Comment:
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
I can think of three reasons off the top of my head.
1.
Generally, including the code which generated your output (figures, tables, p-values, etc.) makes it easier for other people (including future-you) to replicate and check the analyses, and I've found that it cuts down on my tendency to lose code.

 1. Including the code that produced the output in the output file itself makes it really easy to '''update analyses when more data becomes available''', although you still would have to re-write the text if anything substantial changes :)
 2. It also makes it easier for other people (including future-you) to '''understand and reproduce your analysis''', and can help you check and correct problems or bugs in your analysis.
 3. Keeping everything together in one document also helps '''prevent lost code''' for generating figures/tables/analyses in a separate output document (like a previous manuscript).

It's also just really easy to do, especially if you're already using LaTeX. Even if you're not, you can create [[http://daringfireball.net/projects/markdown/|markdown]] documents which are easy to read and can be quickly converted into HTML.
Line 22: Line 27:

The quickest way to get started is to download [[http://www.rstudio.com/|RStudio]], which has built in support for knitr processing of LaTeX, HTML, and markdown. Open up preferences, click on 'Sweave', and change 'Weave Rnw files using ...' to knitr.

Knitr: automatic report generation

What does it do?

Knitr is an R package which allows direct embedding of code (R, Python, etc.) inside documents (LaTeX, HTML, Markdown, etc.). At the most basic level, this means no more copy and pasting or retyping of generated quantities, no more \includegraphics{} and pdf() or ggsave() calls in R, and no more typing scads of LMER coefficients.

What Knitr actually does is to scan the document, extract all the code chunks, evaluate them, format the results in a nice way (that you can control), and insert them back into the document, which can then be compiled in whatever way is appropriate (pdflatex for a LaTeX document, or a web browser/markdown interpreter for HTML or markdown output).

Knitr is based on Sweave, but is a lot better. There's automatic cacheing (so that a document can be re-knit without re-running code that hasn't changed since the last knitting, like time-consuming data analysis code), more transparency (can include all input and output in the final document, as if you ran the code chunks in an R console), pretty formatting of R code and results in LaTeX, and a more modular interface which is easy to hack and expand.

Why would I want to do that??

Generally, including the code which generated your output (figures, tables, p-values, etc.) makes it easier for other people (including future-you) to replicate and check the analyses, and I've found that it cuts down on my tendency to lose code.

  1. Including the code that produced the output in the output file itself makes it really easy to update analyses when more data becomes available, although you still would have to re-write the text if anything substantial changes :)

  2. It also makes it easier for other people (including future-you) to understand and reproduce your analysis, and can help you check and correct problems or bugs in your analysis.

  3. Keeping everything together in one document also helps prevent lost code for generating figures/tables/analyses in a separate output document (like a previous manuscript).

It's also just really easy to do, especially if you're already using LaTeX. Even if you're not, you can create markdown documents which are easy to read and can be quickly converted into HTML.

How do I do it?

The quickest way to get started is to download RStudio, which has built in support for knitr processing of LaTeX, HTML, and markdown. Open up preferences, click on 'Sweave', and change 'Weave Rnw files using ...' to knitr.

LabmeetingSP13w13 (last edited 2013-10-16 03:31:19 by cpe-74-74-158-116)

MoinMoin Appliance - Powered by TurnKey Linux