emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] question about chaining function calls in org-babel


From: Inquisitive Scientist
Subject: [Orgmode] question about chaining function calls in org-babel
Date: Wed, 4 Aug 2010 20:19:16 -0400

Dear Experts,

I think org-babel is awesome but I'm having some trouble chaining
together multiple function calls.

Specifically, I would like to do something like the following
#+tblname: fancier
| mean   |
|--------|
| #ERROR |
#+TBLFM: @2$1='(sbe "python-mean" (x (sbe "tbl-example-data" (seed 4) (size (sbe "square" (x 4))))))
but it doesn't work.

Can someone help me understand:
  1. How to make this work?
  2. How to debug things like this (e.g., how do I make something
     appearing in a table get its own session so I can use
     org-babel-pop-to-session)?

Supporting code and building up examples to try to make the above work
are shown below.

The following builds up examples for multiple function calls. Save
this in org-mode and see what happens.

Create a block to generate random data:
#+srcname: tbl-example-data(seed=2, size=3)
#+begin_src python :
import random
random.seed(seed)
return [i+random.gauss(0,.1) for i in range(size)]
#+end_src

Create a block to compute the mean
#+srcname: python-mean(x)
#+begin_src python
return sum(x)/float(len(x))
#+end_src

Create a table to use the data. To update the table do "C-u C-c *" in
the table.
#+tblname: summaries
|          mean |
|---------------|
| 1.06900574831 |
#+TBLFM: @2$1='(sbe "python-mean" (x "tbl-example-data"))

Create a table to use the data where we pass arguments to
tbl-example-data. To update the table do "C-u C-c *" in the table.
#+tblname: fancy
|          mean |
|---------------|
| 3.53014887192 |
#+TBLFM: @2$1='(sbe "python-mean" (x "tbl-example-data(seed=4,size=8)"))

Define a square function:
#+srcname: square(x)
#+begin_src python
return x*x
#+end_src

Test squaring:
#+tblname: testSquaring
| mean |
|------|
|   16 |
#+TBLFM: @2$1='(sbe "square" (x 4))


Try to do something even fancier and it doesn't work:
#+tblname: fancier
| mean |
|------|
|      |
#+TBLFM: @2$1='(sbe "python-mean" (x "tbl-example-data(seed=4,size=square(4))"))

Try to do something even fancier with sbe and it doesn't work.
#+tblname: fancier
| mean |
|------|
|      |
#+TBLFM: @2$1='(sbe "python-mean" (x (sbe "tbl-example-data" (seed 4) (size square(4)))))

One more try:
#+tblname: fancier
| mean   |
|--------|
| #ERROR |
#+TBLFM: @2$1='(sbe "python-mean" (x (sbe "tbl-example-data" (seed 4) (size (sbe "square" (x 4))))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]