emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] Problems assigning tables as variables using #+CALL and using properties in code blocks and sbe calls
@ 2013-07-19  0:34 Torsten Wagner
  2013-07-19  1:06 ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Torsten Wagner @ 2013-07-19  0:34 UTC (permalink / raw)
  To: Org Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 1024 bytes --]

Hi,
I have a tables like this:

#+TBLNAME: tablename
| a | b |c | d |
| 1 | 2 |3  |4 |
| z | x | y |w|

#+TBLNAME: othertablename
| a | b |c | d |
| 1 | 2 |3  |4 |
| z | x | y |w|

I have the following code block

#+name: test
#+begin_src python :var table=tablename :exports results
import numpy as np
tab = np.array(table)
return np.array([tab[:,1], tab[:,-1]]).T
#+end_src

If I call that function the result is correct

However using

#+CALL: aushang[:var table=othertablename]() :exports results
or
#+CALL: aushang(table=othertablename) :exports results

does not work. It seem the babel block does not get the table but something
else in case its called by #+CALL:.
In general, how-to refer to a table in #+CALL blocks?

On a similar line: I used $PROP_name to use property values within the sbe
function.
However, how to use the same property as input to a code-block?

+begin_src python :var x=$PROP_name :exports results
and
+begin_src python :var x=name :exports results

did not work

Any ideas?

Thanks

Torsten

[-- Attachment #2: Type: text/html, Size: 1419 bytes --]

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

* Re: [babel] Problems assigning tables as variables using #+CALL and using properties in code blocks and sbe calls
  2013-07-19  0:34 [babel] Problems assigning tables as variables using #+CALL and using properties in code blocks and sbe calls Torsten Wagner
@ 2013-07-19  1:06 ` Eric Schulte
  2013-07-19 11:06   ` Torsten Wagner
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2013-07-19  1:06 UTC (permalink / raw)
  To: Torsten Wagner; +Cc: Org Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 998 bytes --]

Torsten Wagner <torsten.wagner@gmail.com> writes:

> Hi,
> I have a tables like this:
>
> #+TBLNAME: tablename
> | a | b |c | d |
> | 1 | 2 |3  |4 |
> | z | x | y |w|
>
> #+TBLNAME: othertablename
> | a | b |c | d |
> | 1 | 2 |3  |4 |
> | z | x | y |w|
>
> I have the following code block
>
> #+name: test
> #+begin_src python :var table=tablename :exports results
> import numpy as np
> tab = np.array(table)
> return np.array([tab[:,1], tab[:,-1]]).T
> #+end_src
>
> If I call that function the result is correct
>
> However using
>
> #+CALL: aushang[:var table=othertablename]() :exports results
> or
> #+CALL: aushang(table=othertablename) :exports results
>
> does not work. It seem the babel block does not get the table but something
> else in case its called by #+CALL:.
> In general, how-to refer to a table in #+CALL blocks?
>

Your tables are identical, and you're not calling the test function in
your call blocks.  A more reasonable (to me) version of your example
works as expected.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: table-call.org --]
[-- Type: text/x-org, Size: 665 bytes --]

#+TBLNAME: tablename
| a | b | c | d |
| 1 | 2 | 3 | 4 |
| z | x | y | w |

#+TBLNAME: othertablename
| a | b | c | d |
| 4 | 3 | 2 | 1 |
| z | x | y | w |

I have the following code block

#+name: test
#+begin_src python :var table=tablename :exports results
  import numpy as np
  tab = np.array(table)
  return np.array([tab[:,1], tab[:,-1]]).T
#+end_src

#+RESULTS: test
| b | d |
| 2 | 4 |
| x | w |

If I call that function the result is correct

However using

#+CALL: test[:var table=othertablename]() :exports results

#+RESULTS:
| b | d |
| 3 | 1 |
| x | w |

#+CALL: test(table=othertablename) :exports results

#+RESULTS:
| b | d |
| 3 | 1 |
| x | w |


[-- Attachment #3: Type: text/plain, Size: 611 bytes --]


>
> On a similar line: I used $PROP_name to use property values within the
> sbe function.  However, how to use the same property as input to a
> code-block?
>
> +begin_src python :var x=$PROP_name :exports results
> and
> +begin_src python :var x=name :exports results
>
> did not work
>
> Any ideas?
>

I don't understand the later part of this email, perhaps an example
would clarify.  Also, it might be worth looking in the following to see
if something matching your use case appears.

  http://eschulte.github.io/org-scraps/

Cheers,

>
> Thanks
>
> Torsten

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

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

* Re: [babel] Problems assigning tables as variables using #+CALL and using properties in code blocks and sbe calls
  2013-07-19  1:06 ` Eric Schulte
@ 2013-07-19 11:06   ` Torsten Wagner
  2013-07-19 15:57     ` Torsten Wagner
  0 siblings, 1 reply; 5+ messages in thread
From: Torsten Wagner @ 2013-07-19 11:06 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode Mailing List


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

Hi Eric,

thanks you so much for always being so responsive to my silly questions :)
I apologize, I wrote that mail 2 am after fiddling around with that problem
for about 3 hours.
Trying to reduce the problem to a minimal example, I almost built in stupid
errors.
I was holding back to send examples as org-file attachment because I
believe that attachments can't be parsed by the different mailing list
archives and thus, any infos there are not searchable. However, I guess in
the future I will simple paste the example and attach a org-file (which in
turn I can really test before sending).

Ok back on track. My problem seems to be quite strange. It is not exactly
related to babel but more about the interface babel + python. Taking your
example, I modified it to reflect my problem

//-------------------------- content of
table-calls.org--------------------------------------------------------

#+TBLNAME: tablename
|   | Name | StudentID | 1.1 | 1.2 | 1.3 | 1.4 | 2.1 | 2.2 | 2.3 | 2.4 |
2.5 | Sum 1 | Sum 2 | Total Sum | Mark | Remark |
|---+------+-----------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-------+-------+-----------+------+--------|
| # | Mr A |     11111 |   0 |  12 |   0 |   0 |  17 |   8 |  10 |   0 |
0 |    12 |    35 |        47 |    5 |        |
| # | Ms B |     22222 |   1 |   2 |   3 |   4 |   5 |   2 |   3 |   4 |
5 |    10 |    19 |        29 |    5 | second |

I have the following code block

#+name: test
#+begin_src python :var table=tablename :exports results
  return type(table[1])
#+end_src

#+RESULTS: test
: <class 'list'>

If I call that function the result is correct

However using

#+CALL: test[:var table=tablename]() :exports results

#+RESULTS: test[:var table=tablename]():exports results
: <class 'NoneType'>

#+CALL: test(table=tablename) :exports results

#+RESULTS: test(table=tablename):exports results
: <class 'NoneType'>

//
------------------------------------------------------end----------------------------------------------------------------

I think I get a bit further with the trouble shooting. As you can see, the
problem seems to be
Calling the source code block directly table seems to be of type list which
is (I guess) correct
However, calling the code via a #+CALL line, the input data (table) is of
type 'NoneType'.
This hoax the later operation in a very strange way. E.g. plan return of
the table is fine, even table[i] works,
more complex operations don't.

The question for me is, why is there a difference of the data (table) type
depending on the call?


As for the second part of the email, again sorry I was kind of tired.
Take I have this property drawer

*** Exam evaluation :intern:
    :PROPERTIES:
    :passscore: 50
    :extrapoints: 1
    :END:

and within a table formula line e.g.
'(sbe score2mark (score $15) (passscore "$PROP_passscore")

This works well, now I want to use the same property as value of a source
code block

Those fail:
#+CALL: createscoretable(passscore=passscore) :exports results
#+CALL: createscoretable(passscore) :exports results
#+CALL: createscoretable($PROP_passscore) :exports results
#+CALL: createscoretable(passscore=$PROPpassscore) :exports results

I can see how to assign a property defined variable to a code block call.
I tried modifications like
*** Exam evaluation :intern:
    :PROPERTIES:
    :var: passscore=50
    :extrapoints: 1
    :END:
and
#+PROPERTY: var  passscore=50

But none of them seem to work for me. Even if one work, would it work
together with the way sbe calls property values?


Basically, I want to use a variable defined in a Property-Drawer for both
the sbe function within table formulars and as value for functions calls of
source code blocks


Thanks again for all your help!

All the best

Torsten








On 19 July 2013 03:06, Eric Schulte <schulte.eric@gmail.com> wrote:

> Torsten Wagner <torsten.wagner@gmail.com> writes:
>
> > Hi,
> > I have a tables like this:
> >
> > #+TBLNAME: tablename
> > | a | b |c | d |
> > | 1 | 2 |3  |4 |
> > | z | x | y |w|
> >
> > #+TBLNAME: othertablename
> > | a | b |c | d |
> > | 1 | 2 |3  |4 |
> > | z | x | y |w|
> >
> > I have the following code block
> >
> > #+name: test
> > #+begin_src python :var table=tablename :exports results
> > import numpy as np
> > tab = np.array(table)
> > return np.array([tab[:,1], tab[:,-1]]).T
> > #+end_src
> >
> > If I call that function the result is correct
> >
> > However using
> >
> > #+CALL: aushang[:var table=othertablename]() :exports results
> > or
> > #+CALL: aushang(table=othertablename) :exports results
> >
> > does not work. It seem the babel block does not get the table but
> something
> > else in case its called by #+CALL:.
> > In general, how-to refer to a table in #+CALL blocks?
> >
>
> Your tables are identical, and you're not calling the test function in
> your call blocks.  A more reasonable (to me) version of your example
> works as expected.
>
>
>
> >
> > On a similar line: I used $PROP_name to use property values within the
> > sbe function.  However, how to use the same property as input to a
> > code-block?
> >
> > +begin_src python :var x=$PROP_name :exports results
> > and
> > +begin_src python :var x=name :exports results
> >
> > did not work
> >
> > Any ideas?
> >
>
> I don't understand the later part of this email, perhaps an example
> would clarify.  Also, it might be worth looking in the following to see
> if something matching your use case appears.
>
>   http://eschulte.github.io/org-scraps/
>
> Cheers,
>
> >
> > Thanks
> >
> > Torsten
>
> --
> Eric Schulte
> http://cs.unm.edu/~eschulte
>
>

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

[-- Attachment #2: table-calls.org --]
[-- Type: application/octet-stream, Size: 1032 bytes --]

#+TBLNAME: tablename
|   | Name | StudentID | 1.1 | 1.2 | 1.3 | 1.4 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | Sum 1 | Sum 2 | Total Sum | Mark | Remark |
|---+------+-----------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-------+-------+-----------+------+--------|
| # | Mr A |     11111 |   0 |  12 |   0 |   0 |  17 |   8 |  10 |   0 |   0 |    12 |    35 |        47 |    5 |        |
| # | Ms B |     22222 |   1 |   2 |   3 |   4 |   5 |   2 |   3 |   4 |   5 |    10 |    19 |        29 |    5 | second |

I have the following code block

#+name: test
#+begin_src python :var table=tablename :exports results
  return type(table[1])
#+end_src

#+RESULTS: test
: <class 'list'>

If I call that function the result is correct

However using

#+CALL: test[:var table=tablename]() :exports results

#+RESULTS: test[:var table=tablename]():exports results
: <class 'NoneType'>

#+CALL: test(table=tablename) :exports results

#+RESULTS: test(table=tablename):exports results
: <class 'NoneType'>



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

* Re: [babel] Problems assigning tables as variables using #+CALL and using properties in code blocks and sbe calls
  2013-07-19 11:06   ` Torsten Wagner
@ 2013-07-19 15:57     ` Torsten Wagner
  2013-07-19 17:56       ` Rick Frankel
  0 siblings, 1 reply; 5+ messages in thread
From: Torsten Wagner @ 2013-07-19 15:57 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 6360 bytes --]

Hi Eric,

one mini-step forward.
The #+CALL function does not work if the table has a horizontal line like in
#+TBLNAME: othertablename
| a | b | c | d |
|---+---+---+---|
| 4 | 3 | 2 | 1 |
| z | x | y | w |

however, it works for

#+TBLNAME: othertablename
| a | b | c | d |
| 4 | 3 | 2 | 1 |
| z | x | y | w |

I guess we come closer to the problem ;)

Thanks for all the help

Torsten



On 19 July 2013 13:06, Torsten Wagner <torsten.wagner@gmail.com> wrote:

> Hi Eric,
>
> thanks you so much for always being so responsive to my silly questions :)
> I apologize, I wrote that mail 2 am after fiddling around with that
> problem for about 3 hours.
> Trying to reduce the problem to a minimal example, I almost built in
> stupid errors.
> I was holding back to send examples as org-file attachment because I
> believe that attachments can't be parsed by the different mailing list
> archives and thus, any infos there are not searchable. However, I guess in
> the future I will simple paste the example and attach a org-file (which in
> turn I can really test before sending).
>
> Ok back on track. My problem seems to be quite strange. It is not exactly
> related to babel but more about the interface babel + python. Taking your
> example, I modified it to reflect my problem
>
> //-------------------------- content of
> table-calls.org--------------------------------------------------------
>
> #+TBLNAME: tablename
> |   | Name | StudentID | 1.1 | 1.2 | 1.3 | 1.4 | 2.1 | 2.2 | 2.3 | 2.4 |
> 2.5 | Sum 1 | Sum 2 | Total Sum | Mark | Remark |
>
> |---+------+-----------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-------+-------+-----------+------+--------|
> | # | Mr A |     11111 |   0 |  12 |   0 |   0 |  17 |   8 |  10 |   0 |
> 0 |    12 |    35 |        47 |    5 |        |
> | # | Ms B |     22222 |   1 |   2 |   3 |   4 |   5 |   2 |   3 |   4 |
> 5 |    10 |    19 |        29 |    5 | second |
>
>
> I have the following code block
>
> #+name: test
> #+begin_src python :var table=tablename :exports results
>   return type(table[1])
> #+end_src
>
> #+RESULTS: test
> : <class 'list'>
>
>
> If I call that function the result is correct
>
> However using
>
> #+CALL: test[:var table=tablename]() :exports results
>
> #+RESULTS: test[:var table=tablename]():exports results
> : <class 'NoneType'>
>
> #+CALL: test(table=tablename) :exports results
>
> #+RESULTS: test(table=tablename):exports results
> : <class 'NoneType'>
>
> //
> ------------------------------------------------------end----------------------------------------------------------------
>
> I think I get a bit further with the trouble shooting. As you can see, the
> problem seems to be
> Calling the source code block directly table seems to be of type list
> which is (I guess) correct
> However, calling the code via a #+CALL line, the input data (table) is of
> type 'NoneType'.
> This hoax the later operation in a very strange way. E.g. plan return of
> the table is fine, even table[i] works,
> more complex operations don't.
>
> The question for me is, why is there a difference of the data (table) type
> depending on the call?
>
>
> As for the second part of the email, again sorry I was kind of tired.
> Take I have this property drawer
>
> *** Exam evaluation :intern:
>     :PROPERTIES:
>     :passscore: 50
>     :extrapoints: 1
>     :END:
>
> and within a table formula line e.g.
> '(sbe score2mark (score $15) (passscore "$PROP_passscore")
>
> This works well, now I want to use the same property as value of a source
> code block
>
> Those fail:
> #+CALL: createscoretable(passscore=passscore) :exports results
> #+CALL: createscoretable(passscore) :exports results
> #+CALL: createscoretable($PROP_passscore) :exports results
> #+CALL: createscoretable(passscore=$PROPpassscore) :exports results
>
> I can see how to assign a property defined variable to a code block call.
> I tried modifications like
> *** Exam evaluation :intern:
>     :PROPERTIES:
>     :var: passscore=50
>     :extrapoints: 1
>     :END:
> and
> #+PROPERTY: var  passscore=50
>
> But none of them seem to work for me. Even if one work, would it work
> together with the way sbe calls property values?
>
>
> Basically, I want to use a variable defined in a Property-Drawer for both
> the sbe function within table formulars and as value for functions calls of
> source code blocks
>
>
> Thanks again for all your help!
>
> All the best
>
> Torsten
>
>
>
>
>
>
>
>
> On 19 July 2013 03:06, Eric Schulte <schulte.eric@gmail.com> wrote:
>
>> Torsten Wagner <torsten.wagner@gmail.com> writes:
>>
>> > Hi,
>> > I have a tables like this:
>> >
>> > #+TBLNAME: tablename
>> > | a | b |c | d |
>> > | 1 | 2 |3  |4 |
>> > | z | x | y |w|
>> >
>> > #+TBLNAME: othertablename
>> > | a | b |c | d |
>> > | 1 | 2 |3  |4 |
>> > | z | x | y |w|
>> >
>> > I have the following code block
>> >
>> > #+name: test
>> > #+begin_src python :var table=tablename :exports results
>> > import numpy as np
>> > tab = np.array(table)
>> > return np.array([tab[:,1], tab[:,-1]]).T
>> > #+end_src
>> >
>> > If I call that function the result is correct
>> >
>> > However using
>> >
>> > #+CALL: aushang[:var table=othertablename]() :exports results
>> > or
>> > #+CALL: aushang(table=othertablename) :exports results
>> >
>> > does not work. It seem the babel block does not get the table but
>> something
>> > else in case its called by #+CALL:.
>> > In general, how-to refer to a table in #+CALL blocks?
>> >
>>
>> Your tables are identical, and you're not calling the test function in
>> your call blocks.  A more reasonable (to me) version of your example
>> works as expected.
>>
>>
>>
>> >
>> > On a similar line: I used $PROP_name to use property values within the
>> > sbe function.  However, how to use the same property as input to a
>> > code-block?
>> >
>> > +begin_src python :var x=$PROP_name :exports results
>> > and
>> > +begin_src python :var x=name :exports results
>> >
>> > did not work
>> >
>> > Any ideas?
>> >
>>
>> I don't understand the later part of this email, perhaps an example
>> would clarify.  Also, it might be worth looking in the following to see
>> if something matching your use case appears.
>>
>>   http://eschulte.github.io/org-scraps/
>>
>> Cheers,
>>
>> >
>> > Thanks
>> >
>> > Torsten
>>
>> --
>> Eric Schulte
>> http://cs.unm.edu/~eschulte
>>
>>
>

[-- Attachment #2: Type: text/html, Size: 8372 bytes --]

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

* Re: [babel] Problems assigning tables as variables using #+CALL and using properties in code blocks and sbe calls
  2013-07-19 15:57     ` Torsten Wagner
@ 2013-07-19 17:56       ` Rick Frankel
  0 siblings, 0 replies; 5+ messages in thread
From: Rick Frankel @ 2013-07-19 17:56 UTC (permalink / raw)
  To: Torsten Wagner; +Cc: Org Mode Mailing List, Eric Schulte

On 2013-07-19 11:57, Torsten Wagner wrote:
> Hi Eric,
> 
> one mini-step forward.
> The #+CALL function does not work if the table has a horizontal line 
> like in
> #+TBLNAME: othertablename
> | a | b | c | d |
> |---+---+---+---|
> | 4 | 3 | 2 | 1 |
> | z | x | y | w |
> 
> however, it works for
> 
> #+TBLNAME: othertablename
> | a | b | c | d |
> | 4 | 3 | 2 | 1 |
> | z | x | y | w |
> 
> I guess we come closer to the problem ;)
> 

This is, i believe related to the general problems I have been seeing
with the processing of tables passed as arguments to babel blocks vs.
the same tables passed to `call' lines. For example:

#+BEGIN_ORG
#+name: ptable
| head1 | head2 |
|-------+-------|
| a     |     1 |
| b     |     2 |

#+name: ptable-mirror
#+BEGIN_SRC python :var t=ptable :results value :colnames no
	return t
#+END_SRC

#+RESULTS: ptable-mirror
| head1 | head2 |
| a     |     1 |
| b     |     2 |

#+call: ptable-mirror()

#+RESULTS:
| head1 | head2 |
| a     |     1 |
| b     |     2 |

#+call: ptable-mirror(t=ptable)

#+RESULTS:
| head1 | head2 |
|-------+-------|
| a     |     1 |
| b     |     2 |
#+END_ORG

As you can see, the handling of headers/colnames is different in a
`call' depending on if the argument is specified explicitly or not.

BTW, changing `colnames no' to `:colnames yes' results in:

#+BEGIN_ORG
#+call: ptable-mirror(t=ptable)

#+RESULTS:
| head1 | head2 |
|-------+-------|
| head1 | head2 |
|-------+-------|
| a     |     1 |
| b     |     2 |
#+END_ORG

rick

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

end of thread, other threads:[~2013-07-19 17:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-19  0:34 [babel] Problems assigning tables as variables using #+CALL and using properties in code blocks and sbe calls Torsten Wagner
2013-07-19  1:06 ` Eric Schulte
2013-07-19 11:06   ` Torsten Wagner
2013-07-19 15:57     ` Torsten Wagner
2013-07-19 17:56       ` Rick Frankel

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