emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [org-babel] Feature request: Get a scalar for "data=example-table[0, 1]"
@ 2010-04-21 14:37 Darlan Cavalcante Moreira
  2010-04-21 15:43 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Darlan Cavalcante Moreira @ 2010-04-21 14:37 UTC (permalink / raw)
  To: emacs-orgmode

In the org-babel documentation we see that one can pass a single element
from a table to a babel source block with
,----
! :var data=example-table[0,1]
`----

I assumed that I would get a scalar value, but it seems that I still get a
table (but with only one element). For instance, if I have the table below

#+TBLNAME: MyTable
 |   X |  Y |
 |-----+----|
 |   0 |  0 |
 |   1 |  1 |
 |   2 |  4 |
 |   3 |  9 |
 |   4 | 16 |
 |   5 | 25 |
 |-----+----|
 | Sum | 55 |
 #+TBLFM: $2=$1*$1::@8$2=vsum(@2..@-1)

then the code in python to print the value of sum returns

,----
! #+begin_src python :var sum=MyTable[9,1] :results output :exports none
!    print sum
! #+end_src
!
! #+results:
! : [[55]]
`----

but I would expect to get only 55, since I'm getting a specific element in
MyTable and not a sub-table.

In addition, the hlines are being counted. Is this intended behaviour? I
remember that there is a thread in the list about keeping the hlines in
resulting tables, but even if that is desirable, counting the hlines as
lines will result in troubles (python give me an error if I use
sum=MyTable[9,1], for instance).


I was trying to plot the table with Org-Babel and Gnuplot with the code below

#+begin_src gnuplot :var data=MyTable[1:-2] :var sum=MyTable[7,1]
:results silent :exports none
  reset
  set label "Sum: %.0f",sum at graph 0.03, graph 0.93
  plot data with linespoints
#+end_src

but the sum variable will have the value of a temporary file with the
element [7,1] instead of the actual value. I could use ":var sum=55" but
then I would have to change this whenever I change the table.


- Darlan

ps: How do I do that "cute here start/end"? Is it gnus functionality (I use
wanderlust) or it is more general?

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

* Re: [org-babel] Feature request: Get a scalar for "data=example-table[0, 1]"
  2010-04-21 14:37 [org-babel] Feature request: Get a scalar for "data=example-table[0, 1]" Darlan Cavalcante Moreira
@ 2010-04-21 15:43 ` Eric Schulte
  2010-04-21 19:08   ` Darlan Cavalcante Moreira
  2010-04-22 15:49   ` OT: message-mark-inserted-region WAS: " Dan Davison
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Schulte @ 2010-04-21 15:43 UTC (permalink / raw)
  To: Darlan Cavalcante Moreira; +Cc: emacs-orgmode

Hi Darlan,

Darlan Cavalcante Moreira <darcamo@gmail.com> writes:

> In the org-babel documentation we see that one can pass a single element
> from a table to a babel source block with
> ,----
> ! :var data=example-table[0,1]
> `----
>
> I assumed that I would get a scalar value, but it seems that I still get a
> table (but with only one element). For instance, if I have the table below
>
> #+TBLNAME: MyTable
>  |   X |  Y |
>  |-----+----|
>  |   0 |  0 |
>  |   1 |  1 |
>  |   2 |  4 |
>  |   3 |  9 |
>  |   4 | 16 |
>  |   5 | 25 |
>  |-----+----|
>  | Sum | 55 |
>  #+TBLFM: $2=$1*$1::@8$2=vsum(@2..@-1)
>
> then the code in python to print the value of sum returns
>
> ,----
> ! #+begin_src python :var sum=MyTable[9,1] :results output :exports none
> !    print sum
> ! #+end_src
> !
> ! #+results:
> ! : [[55]]
> `----
>
> but I would expect to get only 55, since I'm getting a specific element in
> MyTable and not a sub-table.
>

I see.  Yes I agree it would be more intuitive if we convert trivial
lists to scalars.  I'm pushing up this change to the indexing behavior,
thanks for the suggestion!

Now your example above behaves as follows...

--8<---------------cut here---------------start------------->8---
#+TBLNAME: MyTable
 |   X |  Y |
 |-----+----|
 |   0 |  0 |
 |   1 |  1 |
 |   2 |  4 |
 |   3 |  9 |
 |   4 | 16 |
 |   5 | 25 |
 |-----+----|
 | Sum | 55 |
 #+TBLFM: $2=$1*$1::@8$2=vsum(@2..@-1)

#+begin_src python :var sum=MyTable[2:7,1] :exports none
   return sum
#+end_src

#+results:
| 0 | 1 | 4 | 9 | 16 | 25 |

#+begin_src python :var sum=MyTable[9,1] :exports none
   return sum
#+end_src

#+results:
: 55
--8<---------------cut here---------------end--------------->8---

>
> In addition, the hlines are being counted. Is this intended behaviour?

Unfortunately there is no clean way (at least that I am aware of) to
handle 'hlines *before* the table indexing code has a crack at parsing
the table.  I suppose we could simply strip out all hlines whenever a
table is being indexed, but I'm not sure if that's always desirable...

> I remember that there is a thread in the list about keeping the hlines
> in resulting tables, but even if that is desirable, counting the
> hlines as lines will result in troubles (python give me an error if I
> use sum=MyTable[9,1], for instance).
>

This is a more general problem.  As it happens Dan and I are currently
testing an update which will introduce some new header arguments to deal
with this issue exactly .  It's still a little too green to inflict on a
wider audience, but trust me when I say that relief is on the horizon.

>
>
> I was trying to plot the table with Org-Babel and Gnuplot with the code below
>
> #+begin_src gnuplot :var data=MyTable[1:-2] :var sum=MyTable[7,1]
> :results silent :exports none
>   reset
>   set label "Sum: %.0f",sum at graph 0.03, graph 0.93
>   plot data with linespoints
> #+end_src
>
> but the sum variable will have the value of a temporary file with the
> element [7,1] instead of the actual value. I could use ":var sum=55" but
> then I would have to change this whenever I change the table.
>

For a short email this is packed with probing questions. :)

This has to do with passing literal values to gnuplot (as opposed to
tables).  When gnuplot receives a vector it drops it to a table and
replaces the variable with the table (so gnuplot can pull the values
out), when it receives a scalar it just drops the scalar value directly
into the code.

The above indexing fix should also fix this problem.

Best -- Eric

>
>
> - Darlan
>
> ps: How do I do that "cute here start/end"? Is it gnus functionality (I use
> wanderlust) or it is more general?
>

The function is called `message-mark-inserted-region' and is part of
message.el which I believe is distributed with Emacs (can't be sure).

>
>
> _______________________________________________
> 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: [org-babel] Feature request: Get a scalar for "data=example-table[0, 1]"
  2010-04-21 15:43 ` Eric Schulte
@ 2010-04-21 19:08   ` Darlan Cavalcante Moreira
  2010-04-22 15:49   ` OT: message-mark-inserted-region WAS: " Dan Davison
  1 sibling, 0 replies; 4+ messages in thread
From: Darlan Cavalcante Moreira @ 2010-04-21 19:08 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Thank you Eric,
That was much faster then I had expected. :)

It works perfectly now.

Regarding the hlines, I find more intuitive not counting them for indexing,
since this is how table formulas work in org, but I'm OK with whatever
solution you and Dan come up with.

At last, after loading message.el I can now use
message-mark-inserted-region, which is much better than boxquote-region for
code snippets.

Thank you again,
Darlan

2010/4/21 Eric Schulte <schulte.eric@gmail.com>:
> Hi Darlan,
>
> Darlan Cavalcante Moreira <darcamo@gmail.com> writes:
>
>> In the org-babel documentation we see that one can pass a single element
>> from a table to a babel source block with
>> ,----
>> ! :var data=example-table[0,1]
>> `----
>>
>> I assumed that I would get a scalar value, but it seems that I still get a
>> table (but with only one element). For instance, if I have the table below
>>
>> #+TBLNAME: MyTable
>>  |   X |  Y |
>>  |-----+----|
>>  |   0 |  0 |
>>  |   1 |  1 |
>>  |   2 |  4 |
>>  |   3 |  9 |
>>  |   4 | 16 |
>>  |   5 | 25 |
>>  |-----+----|
>>  | Sum | 55 |
>>  #+TBLFM: $2=$1*$1::@8$2=vsum(@2..@-1)
>>
>> then the code in python to print the value of sum returns
>>
>> ,----
>> ! #+begin_src python :var sum=MyTable[9,1] :results output :exports none
>> !    print sum
>> ! #+end_src
>> !
>> ! #+results:
>> ! : [[55]]
>> `----
>>
>> but I would expect to get only 55, since I'm getting a specific element in
>> MyTable and not a sub-table.
>>
>
> I see.  Yes I agree it would be more intuitive if we convert trivial
> lists to scalars.  I'm pushing up this change to the indexing behavior,
> thanks for the suggestion!
>
> Now your example above behaves as follows...
>
> --8<---------------cut here---------------start------------->8---
> #+TBLNAME: MyTable
>  |   X |  Y |
>  |-----+----|
>  |   0 |  0 |
>  |   1 |  1 |
>  |   2 |  4 |
>  |   3 |  9 |
>  |   4 | 16 |
>  |   5 | 25 |
>  |-----+----|
>  | Sum | 55 |
>  #+TBLFM: $2=$1*$1::@8$2=vsum(@2..@-1)
>
> #+begin_src python :var sum=MyTable[2:7,1] :exports none
>   return sum
> #+end_src
>
> #+results:
> | 0 | 1 | 4 | 9 | 16 | 25 |
>
> #+begin_src python :var sum=MyTable[9,1] :exports none
>   return sum
> #+end_src
>
> #+results:
> : 55
> --8<---------------cut here---------------end--------------->8---
>
>>
>> In addition, the hlines are being counted. Is this intended behaviour?
>
> Unfortunately there is no clean way (at least that I am aware of) to
> handle 'hlines *before* the table indexing code has a crack at parsing
> the table.  I suppose we could simply strip out all hlines whenever a
> table is being indexed, but I'm not sure if that's always desirable...
>
>> I remember that there is a thread in the list about keeping the hlines
>> in resulting tables, but even if that is desirable, counting the
>> hlines as lines will result in troubles (python give me an error if I
>> use sum=MyTable[9,1], for instance).
>>
>
> This is a more general problem.  As it happens Dan and I are currently
> testing an update which will introduce some new header arguments to deal
> with this issue exactly .  It's still a little too green to inflict on a
> wider audience, but trust me when I say that relief is on the horizon.
>
>>
>>
>> I was trying to plot the table with Org-Babel and Gnuplot with the code below
>>
>> #+begin_src gnuplot :var data=MyTable[1:-2] :var sum=MyTable[7,1]
>> :results silent :exports none
>>   reset
>>   set label "Sum: %.0f",sum at graph 0.03, graph 0.93
>>   plot data with linespoints
>> #+end_src
>>
>> but the sum variable will have the value of a temporary file with the
>> element [7,1] instead of the actual value. I could use ":var sum=55" but
>> then I would have to change this whenever I change the table.
>>
>
> For a short email this is packed with probing questions. :)
>
> This has to do with passing literal values to gnuplot (as opposed to
> tables).  When gnuplot receives a vector it drops it to a table and
> replaces the variable with the table (so gnuplot can pull the values
> out), when it receives a scalar it just drops the scalar value directly
> into the code.
>
> The above indexing fix should also fix this problem.
>
> Best -- Eric
>
>>
>>
>> - Darlan
>>
>> ps: How do I do that "cute here start/end"? Is it gnus functionality (I use
>> wanderlust) or it is more general?
>>
>
> The function is called `message-mark-inserted-region' and is part of
> message.el which I believe is distributed with Emacs (can't be sure).
>
>>
>>
>> _______________________________________________
>> 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
>



-- 
Darlan Cavalcante Moreira

"SDR4all, a new way of teaching telecommunications: http://www.sdr4all.com/

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

* OT: message-mark-inserted-region WAS: [org-babel] Feature request: Get a scalar for "data=example-table[0, 1]"
  2010-04-21 15:43 ` Eric Schulte
  2010-04-21 19:08   ` Darlan Cavalcante Moreira
@ 2010-04-22 15:49   ` Dan Davison
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Davison @ 2010-04-22 15:49 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Hi Darlan,
>
> Darlan Cavalcante Moreira <darcamo@gmail.com> writes:
[...]
>> - Darlan
>>
>> ps: How do I do that "cute here start/end"? Is it gnus functionality (I use
>> wanderlust) or it is more general?
>>
>
> The function is called `message-mark-inserted-region' and is part of
> message.el which I believe is distributed with Emacs (can't be sure).

Which raises two questions for me:

1. Doesn't the special behaviour in emacs mail clients rather depend on
   people using the same value of message-mark-insert-begin and
   message-mark-insert-end?

2. Which aesthete came up with the default values, and has anyone
   notified the relevant professional artistic organisations of the
   untapped talent?
   
,----
|    message-mark-insert-begin is a variable defined in `message.el'.
|    Its value is 
| "--8<---------------cut here---------------start------------->8---\n"
`----

Oh right, I did (find-library "message") to check the author. That
explains it.

Dan

>
>>
>>
>> _______________________________________________
>> 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
>
>
> _______________________________________________
> 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-04-22 15:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-21 14:37 [org-babel] Feature request: Get a scalar for "data=example-table[0, 1]" Darlan Cavalcante Moreira
2010-04-21 15:43 ` Eric Schulte
2010-04-21 19:08   ` Darlan Cavalcante Moreira
2010-04-22 15:49   ` OT: message-mark-inserted-region WAS: " Dan Davison

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