The Library of Babel

Table of Contents

Introduction

The Library of Babel is an extensible collection of ready-made and easily-shortcut-callable source-code blocks for handling common tasks. Org-babel comes pre-populated with the source-code blocks located in this file. It is possible to add source-code blocks from any org-mode file to the library by calling (org-babel-lob-ingest "path/to/file.org").

This file is included in worg less for viewing through the web interface, and more for contribution through the worg git repository. If you have code snippets that you think others may find useful please add them to this file and contribute them to worg.

To use the Library of Babel,

Plotting code

R

Plot column 2 (y axis) against column 1 (x axis). Columns 3 and beyond, if present, are ignored.

plot(data)
1 2
2 4
3 9
4 16
5 25
nil

Gnuplot

Table/Matrix manipulation

Filtering a table by rows

(defun org-lob-filter-table (table field value)
  (if (and (> (length table) 1)
           (eq (second table) 'hline))
      (append
       (list
        (first table)
        'hline)
       (org-lob-filter-table (cddr table) field value))
    (delq nil
          (mapcar (lambda (row)
                    (cond
                     ((eq row 'hline) 'hline)
                     ((equal (nth field row) value) row)))
                  table))))

(org-lob-filter-table table field value)

Transposing a matrix

Example usage

1 2 3
4 5 6
1 4
2 5
3 6

Binding tables together by columns

Emacs lisp

(mapcar* 'append a b)

R

cbind(a, b)

Example usage

Suppose the tables are

1 2 3
7 8 9
4 5 6
10 11 12
1 2 3 4 5 6
7 8 9 10 11 12

The R code block can also cope with column names:

a b c
1 2 3
7 8 9
d e f
4 5 6
10 11 12

Documentation from the http://orgmode.org/worg/ website (either in its HTML format or in its Org format) is licensed under the GNU Free Documentation License version 1.3 or later. The code examples and css stylesheets are licensed under the GNU General Public License v3 or later.