Sacha on Org Using Org Tables

Sacha Chua has an outstanding post on how to add data to and get data from Org mode tables. I’ve written a lot about using Org tables and what used to be called Babel to calculate results from the tables and insert those results into the same Org buffer. That’s hugely useful for things like reproducible research or even for tracking income tax deductions.

Chua looks at these aspects in detail but also looks at it the other way around. She shows how to export tables and the code associated with it to an external file. She gives the example of a table with some data and a bit of Elisp that processes that data. If you export that code, it takes the data from the table with it in an Elisp usable form. For example given

#+NAME: numbers
| number  | value |
|---------+-------|
| "one"   |     1 |
| "two"   |     2 |
| "three" |     3 | 
  
#+BEGIN_SRC emacs-lisp :exports code :var nums=numbers[2:-1] :tangle yes
  (mapc (lambda (x) (print (format "%s has value %d" (car x) (cadr x)))) nums)
#+END_SRC

the resulting export is

(let ((nums (quote (("one" 1) ("two" 2) ("three" 3)))))
  (mapc (lambda (x) (print (format "%s has value %d" (car x) (cadr x)))) nums))

Notice how the table data has been converted to a let that’s directly usable by Elisp. That’s pretty neat and something I didn’t know. Even better, she shows how to extract data from Org tables and put them someplace else. I use this in a lightweight way to generate a summary table for my tax data but Chua shows some advanced features.

If you want to learn how to leverage Org mode data handling, you should be sure to check out her post.

This entry was posted in General and tagged , . Bookmark the permalink.