From mboxrd@z Thu Jan 1 00:00:00 1970 From: Torsten Wagner Subject: Re: [babel] Problems assigning tables as variables using #+CALL and using properties in code blocks and sbe calls Date: Fri, 19 Jul 2013 13:06:23 +0200 Message-ID: References: <871u6ve4tr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=001a11c275a03da98504e1db5121 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V08W3-000050-Mg for emacs-orgmode@gnu.org; Fri, 19 Jul 2013 07:06:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V08W1-0003Qh-F4 for emacs-orgmode@gnu.org; Fri, 19 Jul 2013 07:06:27 -0400 Received: from mail-ea0-x22c.google.com ([2a00:1450:4013:c01::22c]:54972) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V08W1-0003QY-30 for emacs-orgmode@gnu.org; Fri, 19 Jul 2013 07:06:25 -0400 Received: by mail-ea0-f172.google.com with SMTP id q10so2337474eaj.31 for ; Fri, 19 Jul 2013 04:06:24 -0700 (PDT) In-Reply-To: <871u6ve4tr.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: Org Mode Mailing List --001a11c275a03da98504e1db5121 Content-Type: multipart/alternative; boundary=001a11c275a03da97f04e1db511f --001a11c275a03da97f04e1db511f Content-Type: text/plain; charset=ISO-8859-1 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 : 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 : #+CALL: test(table=tablename) :exports results #+RESULTS: test(table=tablename):exports results : // ------------------------------------------------------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 wrote: > Torsten Wagner 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 > > --001a11c275a03da97f04e1db511f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Eric,

thanks you so muc= h for always being so responsive to my silly questions :)
I apolog= ize, I wrote that mail 2 am after fiddling around with that problem for abo= ut 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 att= achment because I believe that attachments can't be parsed by the diffe= rent mailing list archives and thus, any infos there are not searchable. Ho= wever, I guess in the future I will simple paste the example and attach a o= rg-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. Taki= ng your example, I modified it to reflect my problem

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

#+TBLNAME: tablename=
|=A0=A0 | 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 |=A0=A0=A0=A0= 11111 |=A0=A0 0 |=A0 12 |=A0=A0 0 |=A0=A0 0 |=A0 17 |=A0=A0 8 |=A0 10 |=A0= =A0 0 |=A0=A0 0 |=A0=A0=A0 12 |=A0=A0=A0 35 |=A0=A0=A0=A0=A0=A0=A0 47 |=A0= =A0=A0 5 |=A0=A0=A0=A0=A0=A0=A0 |
| # | Ms B |=A0=A0=A0=A0 22222 |=A0=A0 1 |=A0=A0 2 |=A0=A0 3 |=A0=A0 4 |=A0= =A0 5 |=A0=A0 2 |=A0=A0 3 |=A0=A0 4 |=A0=A0 5 |=A0=A0=A0 10 |=A0=A0=A0 19 |= =A0=A0=A0=A0=A0=A0=A0 29 |=A0=A0=A0 5 | second |

I have the followin= g code block

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

#+RESULTS: test
: <clas= s 'list'>

If I call that function the result is correct
However using

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

#+RESULTS: test[:var table=3Dtablename]():exports results
: <clas= s 'NoneType'>

#+CALL: test(table=3Dtablename) :exports re= sults

#+RESULTS: test(table=3Dtablename):exports results
: <cl= ass 'NoneType'>

// ------------------------------------------------------end= ----------------------------------------------------------------

I think I get a bit further with the trouble shooting. As you can s= ee, 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 vi= a a #+CALL line, the input data (table) is of type 'NoneType'.
This hoax the later operation in a very strange way. E.g. plan r= eturn of the table is fine, even table[i] works,
more complex= operations don't.

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


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

*** Exam evaluatio= n :intern:
=A0=A0=A0 :PROPERTIES:
=A0=A0=A0 :passscore: 50
=A0=A0= =A0 :extrapoints: 1
=A0=A0=A0 :END:

and within a table formula line e.g.
&= #39;(sbe score2mark (score $15) (passscore "$PROP_passscore")
=
This works well, now I want to use the same property as valu= e of a source code block

Those fail:
#+CALL: createscoretable(passscore=3Dpassscor= e) :exports results
#+CALL: createscoretable(passscore) :exports results=
#+CALL: createscoretable($PROP_passscore) :exports results
#+CALL: c= reatescoretable(passscore=3D$PROPpassscore) :exports results

I can see how to assign a property defined variable to a cod= e block call.
I tried modifications like
*** Exam evaluati= on :intern:
=A0=A0=A0 :PROPERTIES:
=A0=A0=A0 :var: passsco= re=3D50
=A0=A0=A0 :extrapoints: 1
=A0=A0=A0 :END:
and <= br>
#+PROPERTY: var=A0 passscore=3D50

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 i= n 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

Torst= en








On 19 July 2013 03:06, = Eric Schulte <schulte.eric@gmail.com> wrote:
Tors= ten Wagner <torsten.wagner@g= mail.com> writes:

> Hi,
> I have a tables like this:
>
> #+TBLNAME: tablename
> | a | b |c | d |
> | 1 | 2 |3 =A0|4 |
> | z | x | y |w|
>
> #+TBLNAME: othertablename
> | a | b |c | d |
> | 1 | 2 |3 =A0|4 |
> | z | x | y |w|
>
> I have the following code block
>
> #+name: test
> #+begin_src python :var table=3Dtablename :exports results
> import numpy as np
> tab =3D 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=3Dothertablename]() :exports results
> or
> #+CALL: aushang(table=3Dothertablename) :exports results
>
> does not work. It seem the babel block does not get the table but some= thing
> 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. =A0A 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. =A0However, how to use the same property as input to a > code-block?
>
> +begin_src python :var x=3D$PROP_name :exports results
> and
> +begin_src python :var x=3Dname :exports results
>
> did not work
>
> Any ideas?
>

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

=A0 htt= p://eschulte.github.io/org-scraps/

Cheers,

>
> Thanks
>
> Torsten

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


--001a11c275a03da97f04e1db511f-- --001a11c275a03da98504e1db5121 Content-Type: application/octet-stream; name="table-calls.org" Content-Disposition: attachment; filename="table-calls.org" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hjb9fyeq1 IytUQkxOQU1FOiB0YWJsZW5hbWUNCnwgICB8IE5hbWUgfCBTdHVkZW50SUQgfCAxLjEgfCAxLjIg fCAxLjMgfCAxLjQgfCAyLjEgfCAyLjIgfCAyLjMgfCAyLjQgfCAyLjUgfCBTdW0gMSB8IFN1bSAy IHwgVG90YWwgU3VtIHwgTWFyayB8IFJlbWFyayB8DQp8LS0tKy0tLS0tLSstLS0tLS0tLS0tLSst LS0tLSstLS0tLSstLS0tLSstLS0tLSstLS0tLSstLS0tLSstLS0tLSstLS0tLSstLS0tLSstLS0t LS0tKy0tLS0tLS0rLS0tLS0tLS0tLS0rLS0tLS0tKy0tLS0tLS0tfA0KfCAjIHwgTXIgQSB8ICAg ICAxMTExMSB8ICAgMCB8ICAxMiB8ICAgMCB8ICAgMCB8ICAxNyB8ICAgOCB8ICAxMCB8ICAgMCB8 ICAgMCB8ICAgIDEyIHwgICAgMzUgfCAgICAgICAgNDcgfCAgICA1IHwgICAgICAgIHwNCnwgIyB8 IE1zIEIgfCAgICAgMj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