Babel: Uses
Table of Contents
Introduction
This page collects examples of using Babel in a variety of contexts. Contributions of further examples from Babel users are very welcome.
Data Collection and Analysis
(raw file available at data-collection-analysis.org)
This example uses Babel to automate a repeated data-collection and analysis task. A Ruby code block is used to scrape data from the output of a computational experiment. This data is then written to an Org-mode table. A block of R code reads from this table and calculates lines of fit. Finally a block of gnuplot code is used to graph the results of both the raw data and the R analysis. By performing all of these steps within an Org-mode document working notes, discussion, and TODOs can be naturally interspersed with the code, and the results can easily be published to HTML or PDF for distribution.
A Research Project
(raw file available at research-project.org)
A research project typically produces one or more documents that describe or rely upon:
- a data collection
- computations and code used in data analysis or simulation
- methodological conventions and assumptions
- decisions among alternate analytic paths
The documents produced by a research project typically stand apart from the things they describe and rely upon, which makes it difficult for other researchers to understand fully or to reproduce the results of the research project.
A software solution to this problem was proposed by Gentleman and Temple Lang, who "introduce the concept of a compendium as both a container for the different elements that make up the document and its computations (i.e. text, code, data, …), and as a means for distributing, managing and updating the collection."
Babel and Org-mode provide the tools needed to create a compendium in one Org-mode file. This example is taken from a work in progress, one that has seen many changes in structure and organization. No claim is made that it is the best way to do things. But it works and is proving extremely useful in the conduct of the research project.
Teaching evolution using R
This example is a tutorial on simulating evolution in R. It contains
examples of diagrams generated with ditaa, LaTeX, and graphics
generated with R.
A good way to see how org-babel functions to create the tutorial is to view the htmlized org buffer. This also provides an example of how images and latex-generated mathematical notation can be viewed inline in emacs. The HTML export version is here.
Checking Your Org-Mode Configuration
(raw file available at org-check.org)
This example runs some diagnostic checks to see if your system and Org-mode are configured to accomplish various tasks. It is currently a stub placed here in the hope that the Org-mode community will augment and enhance it. It was created in response to a thread on the mailing list on how to ease the learning curve for new Org-mode users.
A LaTeX Form
(raw file available at latex-form.org)
This example uses Babel as a user interface for a LaTeX form that might be used by the members of an organization. It uses the literate programming facility of Babel to isolate the user from the sometimes arcane LaTeX constructs needed to create a highly-structured form. Babel can tangle multiple documents in a single Org-mode file, and this ability is used to create a distribution version of the form separate from one designed for the file cabinet.
A Standardized Short Report
(raw file available at short-report.org)
This example is similar to the previous one, but here the users are expected to write substantial content. This type of workflow might be used by a small organization whose employees regularly produce standard documents and where the writing tasks for any one document are divided among the authors.
The HTML export facility of Org-mode is used to produce a guide to writing the standardized short report. This HTML file can be used to train new authors. The Org-mode content also supplies substantial direction to experienced authors as they write. Org-mode keywords and tags are used to keep track of writing assignments and progress. Babel's literate programming facility makes it possible to present writing tasks to the authors in an order different from which they appear in the report.
A Example Using Ascii Package
(raw file available at ascii.org)
This example shows how to use Babel with R and ascii package.
An Babel Demo – A Comparison to Sweave
Charlie Geyer created an excellent short demonstration of Sweave entitled An Sweave Demo available at his Sweave page. There is now an Babel version of this demonstration entitled An Babel Demo which matches Charlie's document word for word (as much as possible) and figure for figure with all the examples implemented using Babel instead of Sweave.
Compare the two side-by-side.
| source | ||
|---|---|---|
| Sweave | foo.Rnw | foo.pdf |
| Babel | foo.org (foo.org.html as seen in Emacs) | foo.pdf |