emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* question about chaining function calls in org-babel
@ 2010-08-05  0:19 Inquisitive Scientist
  2010-08-05  2:08 ` Dan Davison
  0 siblings, 1 reply; 3+ messages in thread
From: Inquisitive Scientist @ 2010-08-05  0:19 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 2311 bytes --]

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))))))

[-- Attachment #1.2: Type: text/html, Size: 2823 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-06  0:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-05  0:19 question about chaining function calls in org-babel Inquisitive Scientist
2010-08-05  2:08 ` Dan Davison
2010-08-06  0:41   ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).