emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Inquisitive Scientist <inquisitive.scientist@gmail.com>
To: emacs-orgmode@gnu.org
Subject: question about chaining function calls in org-babel
Date: Wed, 4 Aug 2010 20:19:16 -0400	[thread overview]
Message-ID: <AANLkTin--bVLyjM_eQH+9n3MnHk5ONQCA8YV+2OS2C05@mail.gmail.com> (raw)


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

             reply	other threads:[~2010-08-05  0:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-05  0:19 Inquisitive Scientist [this message]
2010-08-05  2:08 ` question about chaining function calls in org-babel Dan Davison
2010-08-06  0:41   ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTin--bVLyjM_eQH+9n3MnHk5ONQCA8YV+2OS2C05@mail.gmail.com \
    --to=inquisitive.scientist@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).