* Babel: help with tables and code blocks?
@ 2010-08-08 8:03 Bart Bunting
2010-08-08 19:34 ` Dan Davison
0 siblings, 1 reply; 4+ messages in thread
From: Bart Bunting @ 2010-08-08 8:03 UTC (permalink / raw
To: emacs-orgmode
Hi everyone,
I'm trying to get my head around babel and getting info back into a
table.
The below org file tracks expenses and the perl code simply sums them
up.
The code is working but I now want to get the total back into another table. What I have is not
working can someone tell me what I'm doing wrong here?
Cheers
Bart
* Expenses
#+tblname: expenses
|------------+-----------------------------------+--------|
| Date | What | Amount |
|------------+-----------------------------------+--------|
| 2010-07-26 | Breakfast | 5 |
| 2010-07-26 | groceries | 8.5 |
| 2010-07-26 | butchers - chicken | 5.5 |
| 2010-07-27 | umart - video card, kvm, speakers | 136 |
* Code
#+srcname: totals
#+begin_src perl :var details=expenses[1:-1]
my $total = 0;
foreach my $row (@$details) {
$total += @$row[2];
}
return $total;
#+end_src
#+results: totals
: 155
* Totals
| Total | #ERROR |
#+TBLFM: $2=#+call: totals(details=expenses)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Babel: help with tables and code blocks?
2010-08-08 8:03 Babel: help with tables and code blocks? Bart Bunting
@ 2010-08-08 19:34 ` Dan Davison
2010-08-08 22:20 ` Bart Bunting
0 siblings, 1 reply; 4+ messages in thread
From: Dan Davison @ 2010-08-08 19:34 UTC (permalink / raw
To: Bart Bunting; +Cc: emacs-orgmode
Bart Bunting <bart@bunting.net.au> writes:
> Hi everyone,
>
> I'm trying to get my head around babel and getting info back into a
> table.
>
> The below org file tracks expenses and the perl code simply sums them
> up.
>
> The code is working but I now want to get the total back into another table. What I have is not
> working can someone tell me what I'm doing wrong here?
>
> Cheers
>
> Bart
>
> * Expenses
>
> #+tblname: expenses
> |------------+-----------------------------------+--------|
> | Date | What | Amount |
> |------------+-----------------------------------+--------|
> | 2010-07-26 | Breakfast | 5 |
> | 2010-07-26 | groceries | 8.5 |
> | 2010-07-26 | butchers - chicken | 5.5 |
> | 2010-07-27 | umart - video card, kvm, speakers | 136 |
>
> * Code
>
> #+srcname: totals
> #+begin_src perl :var details=expenses[1:-1]
> my $total = 0;
> foreach my $row (@$details) {
> $total += @$row[2];
> }
>
> return $total;
> #+end_src
>
> #+results: totals
> : 155
>
>
>
> * Totals
>
> | Total | #ERROR |
> #+TBLFM: $2=#+call: totals(details=expenses)
Hi Bart,
You've mixed up #+call and sbe there. sbe is what you want to use in a
table formula; #+call and #+lob are for standalone lines. Here are a few
examples of different ways to do what you're doing. Hopefully they make
things clear.
Dan
--8<---------------cut here---------------start------------->8---
* Totals
** Using a table formula
*** Relying on default argument to totals block
| Total | 155 |
#+TBLFM: $2='(sbe "totals")
*** Providing argument explicitly
The dots are a bug. We'll fix it.
**** version 1
| Total | 155... |
#+TBLFM: $2='(sbe "totals(details=expenses[1:-1])")
**** version 2
| Total | 155... |
#+TBLFM: $2='(sbe "totals" (details "expenses[1:-1]"))
** Using call/lob
#+call and #+lob are synonyms
*** Relying on default argument to totals block
#+call: totals()
#+results: totals()
: 155
or equivalently (it outputs into the same results block):
#+lob: totals()
*** Providing argument explicitly
#+call: totals(details=expenses[1:-1])
#+results: totals(details=expenses[1:-1])
: 155
--8<---------------cut here---------------end--------------->8---
>
> _______________________________________________
> 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] 4+ messages in thread
* Re: Babel: help with tables and code blocks?
2010-08-08 19:34 ` Dan Davison
@ 2010-08-08 22:20 ` Bart Bunting
2010-08-08 22:38 ` Dan Davison
0 siblings, 1 reply; 4+ messages in thread
From: Bart Bunting @ 2010-08-08 22:20 UTC (permalink / raw
To: Dan Davison; +Cc: emacs-orgmode
On Sun, 08 Aug 2010 15:34:02 -0400, Dan Davison <davison@stats.ox.ac.uk> wrote:
Dan,
Thank you very much for that explanation!
This makes the whole thing much clearer.
Do you know where the sbe call is documented in the manual? I couldn't
find it my self.
Thanks again.
Bart
> Bart Bunting <bart@bunting.net.au> writes:
>
> > Hi everyone,
> >
> > I'm trying to get my head around babel and getting info back into a
> > table.
> >
> > The below org file tracks expenses and the perl code simply sums them
> > up.
> >
> > The code is working but I now want to get the total back into another table. What I have is not
> > working can someone tell me what I'm doing wrong here?
> >
> > Cheers
> >
> > Bart
> >
> > * Expenses
> >
> > #+tblname: expenses
> > |------------+-----------------------------------+--------|
> > | Date | What | Amount |
> > |------------+-----------------------------------+--------|
> > | 2010-07-26 | Breakfast | 5 |
> > | 2010-07-26 | groceries | 8.5 |
> > | 2010-07-26 | butchers - chicken | 5.5 |
> > | 2010-07-27 | umart - video card, kvm, speakers | 136 |
> >
> > * Code
> >
> > #+srcname: totals
> > #+begin_src perl :var details=expenses[1:-1]
> > my $total = 0;
> > foreach my $row (@$details) {
> > $total += @$row[2];
> > }
> >
> > return $total;
> > #+end_src
> >
> > #+results: totals
> > : 155
> >
> >
> >
> > * Totals
> >
> > | Total | #ERROR |
> > #+TBLFM: $2=#+call: totals(details=expenses)
>
> Hi Bart,
>
> You've mixed up #+call and sbe there. sbe is what you want to use in a
> table formula; #+call and #+lob are for standalone lines. Here are a few
> examples of different ways to do what you're doing. Hopefully they make
> things clear.
>
> Dan
>
> --8<---------------cut here---------------start------------->8---
>
> * Totals
> ** Using a table formula
>
> *** Relying on default argument to totals block
> | Total | 155 |
> #+TBLFM: $2='(sbe "totals")
>
> *** Providing argument explicitly
>
> The dots are a bug. We'll fix it.
>
> **** version 1
> | Total | 155... |
> #+TBLFM: $2='(sbe "totals(details=expenses[1:-1])")
>
> **** version 2
> | Total | 155... |
> #+TBLFM: $2='(sbe "totals" (details "expenses[1:-1]"))
>
>
> ** Using call/lob
>
> #+call and #+lob are synonyms
>
> *** Relying on default argument to totals block
>
> #+call: totals()
>
> #+results: totals()
> : 155
>
> or equivalently (it outputs into the same results block):
>
> #+lob: totals()
>
> *** Providing argument explicitly
> #+call: totals(details=expenses[1:-1])
>
> #+results: totals(details=expenses[1:-1])
> : 155
>
> --8<---------------cut here---------------end--------------->8---
>
>
>
>
> >
> > _______________________________________________
> > 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
--
Bart Bunting
URSYS Pty. Ltd
13 Burwood Rd. Burwood NSW 2134 Australia
Ph. +61 2 8745 2811
Fax +61 2 8745 2828
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Babel: help with tables and code blocks?
2010-08-08 22:20 ` Bart Bunting
@ 2010-08-08 22:38 ` Dan Davison
0 siblings, 0 replies; 4+ messages in thread
From: Dan Davison @ 2010-08-08 22:38 UTC (permalink / raw
To: Bart Bunting; +Cc: emacs-orgmode
Bart Bunting <bart@bunting.net.au> writes:
> On Sun, 08 Aug 2010 15:34:02 -0400, Dan Davison <davison@stats.ox.ac.uk> wrote:
> Dan,
>
> Thank you very much for that explanation!
>
> This makes the whole thing much clearer.
>
> Do you know where the sbe call is documented in the manual? I couldn't
> find it my self.
It's documented in the original Worg pages here
http://orgmode.org/worg/org-contrib/babel/intro.php#spreadsheet
but you're right, it looks like that information is completely lacking
from the manual. I've added it as a babel development TODO.
Thanks for pointing that out,
Dan
>
> Thanks again.
>
> Bart
>
>
>> Bart Bunting <bart@bunting.net.au> writes:
>>
>> > Hi everyone,
>> >
>> > I'm trying to get my head around babel and getting info back into a
>> > table.
>> >
>> > The below org file tracks expenses and the perl code simply sums them
>> > up.
>> >
>> > The code is working but I now want to get the total back into another table. What I have is not
>> > working can someone tell me what I'm doing wrong here?
>> >
>> > Cheers
>> >
>> > Bart
>> >
>> > * Expenses
>> >
>> > #+tblname: expenses
>> > |------------+-----------------------------------+--------|
>> > | Date | What | Amount |
>> > |------------+-----------------------------------+--------|
>> > | 2010-07-26 | Breakfast | 5 |
>> > | 2010-07-26 | groceries | 8.5 |
>> > | 2010-07-26 | butchers - chicken | 5.5 |
>> > | 2010-07-27 | umart - video card, kvm, speakers | 136 |
>> >
>> > * Code
>> >
>> > #+srcname: totals
>> > #+begin_src perl :var details=expenses[1:-1]
>> > my $total = 0;
>> > foreach my $row (@$details) {
>> > $total += @$row[2];
>> > }
>> >
>> > return $total;
>> > #+end_src
>> >
>> > #+results: totals
>> > : 155
>> >
>> >
>> >
>> > * Totals
>> >
>> > | Total | #ERROR |
>> > #+TBLFM: $2=#+call: totals(details=expenses)
>>
>> Hi Bart,
>>
>> You've mixed up #+call and sbe there. sbe is what you want to use in a
>> table formula; #+call and #+lob are for standalone lines. Here are a few
>> examples of different ways to do what you're doing. Hopefully they make
>> things clear.
>>
>> Dan
>>
>> --8<---------------cut here---------------start------------->8---
>>
>> * Totals
>> ** Using a table formula
>>
>> *** Relying on default argument to totals block
>> | Total | 155 |
>> #+TBLFM: $2='(sbe "totals")
>>
>> *** Providing argument explicitly
>>
>> The dots are a bug. We'll fix it.
>>
>> **** version 1
>> | Total | 155... |
>> #+TBLFM: $2='(sbe "totals(details=expenses[1:-1])")
>>
>> **** version 2
>> | Total | 155... |
>> #+TBLFM: $2='(sbe "totals" (details "expenses[1:-1]"))
>>
>>
>> ** Using call/lob
>>
>> #+call and #+lob are synonyms
>>
>> *** Relying on default argument to totals block
>>
>> #+call: totals()
>>
>> #+results: totals()
>> : 155
>>
>> or equivalently (it outputs into the same results block):
>>
>> #+lob: totals()
>>
>> *** Providing argument explicitly
>> #+call: totals(details=expenses[1:-1])
>>
>> #+results: totals(details=expenses[1:-1])
>> : 155
>>
>> --8<---------------cut here---------------end--------------->8---
>>
>>
>>
>>
>> >
>> > _______________________________________________
>> > 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] 4+ messages in thread
end of thread, other threads:[~2010-08-08 22:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-08 8:03 Babel: help with tables and code blocks? Bart Bunting
2010-08-08 19:34 ` Dan Davison
2010-08-08 22:20 ` Bart Bunting
2010-08-08 22:38 ` Dan Davison
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.