From mboxrd@z Thu Jan 1 00:00:00 1970 From: Inquisitive Scientist Subject: question about chaining function calls in org-babel Date: Wed, 4 Aug 2010 20:19:16 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1311929848==" Return-path: Received: from [140.186.70.92] (port=37978 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgoB4-0004Xa-8r for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 20:19:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OgoB3-0002iO-0T for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 20:19:18 -0400 Received: from mail-gx0-f169.google.com ([209.85.161.169]:51979) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgoB2-0002iJ-TG for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 20:19:16 -0400 Received: by gxk4 with SMTP id 4so3029964gxk.0 for ; Wed, 04 Aug 2010 17:19:16 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --===============1311929848== Content-Type: multipart/alternative; boundary=001485f86272282859048d088013 --001485f86272282859048d088013 Content-Type: text/plain; charset=ISO-8859-1 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)))))) --001485f86272282859048d088013 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Dear Experts,

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

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

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

Sup= porting code and building up examples to try to make the above work
are shown below.

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

Create a b= lock to generate random data:
#+srcname: tbl-example-data(seed=3D2, size= =3D3)
#+begin_src python :
import random
random.seed(seed)
return [i+ran= dom.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 d= ata. To update the table do "C-u C-c *" in
the table.
#+tbl= name: summaries
|=A0=A0=A0=A0=A0=A0=A0=A0=A0 mean |
|---------------|=
| 1.06900574831 |
#+TBLFM: @2$1=3D'(sbe "python-mean" (x "tbl-example-data= "))

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

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

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


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

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

One more try:
#+tblname: fancie= r
| mean=A0=A0 |
|--------|
| #ERROR |
#+TBLFM: @2$1=3D'(sbe "python-mean&quo= t; (x (sbe "tbl-example-data" (seed 4) (size (sbe "square&qu= ot; (x 4))))))

--001485f86272282859048d088013-- --===============1311929848== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --===============1311929848==--