Re: [O] How to pass named table reference in source block variable
Thomas S. Dye tsd at tsdye.com writes: Roland Donat roland.donat at gmail.com writes: Perhaps this can help: http://orgmode.org/worg/org-contrib/babel/examples/lob-table- operations.html Alternatively, you might pass the table to a code block of a language that understands tables, such as an R data frame, and use that language to retrieve values by name. hth, Tom Thank you for the link, I'll check it but seems that it won't solve the problem. But anyway, I found a workaround that doesn't involve to insert table reference. What is the workaround? All the best, Tom Well, my main objective was to write piece of code in a given language X including information stored in some org-table. So my solution for now was to create some python functions able to generate my code. I use babel to pass my org-table as input to the python function and the result is another source block of language X containing the code taking into account the information of my org-table. I recognized that the solution seems quite heavy but I have already developped some python wrapper for my language X so It takes me only 2 hours to do the job. All the best. Roland.
Re: [O] How to pass named table reference in source block variable
Roland Donat roland.do...@gmail.com writes: Thomas S. Dye tsd at tsdye.com writes: Roland Donat roland.donat at gmail.com writes: Perhaps this can help: http://orgmode.org/worg/org-contrib/babel/examples/lob-table- operations.html Alternatively, you might pass the table to a code block of a language that understands tables, such as an R data frame, and use that language to retrieve values by name. hth, Tom Thank you for the link, I'll check it but seems that it won't solve the problem. But anyway, I found a workaround that doesn't involve to insert table reference. What is the workaround? All the best, Tom Well, my main objective was to write piece of code in a given language X including information stored in some org-table. So my solution for now was to create some python functions able to generate my code. I use babel to pass my org-table as input to the python function and the result is another source block of language X containing the code taking into account the information of my org-table. I recognized that the solution seems quite heavy but I have already developped some python wrapper for my language X so It takes me only 2 hours to do the job. All the best. It sounds like you want to use tables like key-value stores. I think adding such behavior directly to Org-mode would overly complicate the data structures passed between code blocks (which currently only consists of scalars and tables). However, maybe the following could work. Here's an example table with key/value data. #+name: table | keys | values | |--+| | foo | 1 | | bar | 2 | | baz | 3 | | qux | 4 | Here's a code block which can access the data in such a table by key. This could be added to the library of babel to make it usable from any Org-mode file. #+name: by-key #+begin_src sh :var data= :var key= echo $data|awk {if(\$1 == \$key\) print \$2} #+end_src And here's an example usage. #+headers: :results verbatim #+begin_src sh :var foo=by-key(table,foo) :var baz=by-key(table,baz) cat EOF Pulling the data from the above table we find that foo is $foo and baz is $baz. EOF #+end_src #+RESULTS: : Pulling the data from the above table we find : that foo is 1 and baz is 3. Cheers, -- Eric Schulte http://cs.unm.edu/~eschulte PGP: 0x614CA05D
Re: [O] How to pass named table reference in source block variable
Eric Schulte schulte.eric at gmail.com writes: It sounds like you want to use tables like key-value stores. I think adding such behavior directly to Org-mode would overly complicate the data structures passed between code blocks (which currently only consists of scalars and tables). However, maybe the following could work. Attachment (key-value.org): text/x-org, 776 bytes Cheers, Thanks for the attachment. It works fine indeed! But should it be so complicated to add this behavior to Org-mode? I can rewrite your table as follows : #+name: table | | keys | values | |---+--+| | | foo | 1 | | ^ | | foo| | | bar | 2 | | ^ | | bar| Now I can refer to bar value as $bar in org-table. So, my suggestion is only to mimic this feature to assign value of source block variable like : #+headers: :results verbatim #+begin_src sh :var foo=table$foo :var bar=table$bar cat EOF Pulling the data from the above table we find that foo is $foo and baz is $bar. EOF #+end_src But anyway, thanks for the solution. Cheers. Roland.
Re: [O] How to pass named table reference in source block variable
Thorsten Jolitz tjolitz at gmail.com writes: This does the job in Emacs Lisp: #+TBLNAME: T | | x | 1 | | ^ | | varx | #+begin_src emacs-lisp :var x=T[0,-1] x #+end_src #+results: : 1 Thanks for the answer but in fact, my objective is precisely to avoid using the indices of the value I want to pass as input of the code block. My goal is to use the cell name reference varx which would make the code block simpler to maintain. Indeed, if I add new data on the top of table T, I wouldn't have to change the reference in the code block since the name reference is fixed.
Re: [O] How to pass named table reference in source block variable
Roland Donat roland.do...@gmail.com writes: Thorsten Jolitz tjolitz at gmail.com writes: This does the job in Emacs Lisp: #+TBLNAME: T | | x | 1 | | ^ | | varx | #+begin_src emacs-lisp :var x=T[0,-1] x #+end_src #+results: : 1 Thanks for the answer but in fact, my objective is precisely to avoid using the indices of the value I want to pass as input of the code block. My goal is to use the cell name reference varx which would make the code block simpler to maintain. Indeed, if I add new data on the top of table T, I wouldn't have to change the reference in the code block since the name reference is fixed. Perhaps this can help: http://orgmode.org/worg/org-contrib/babel/examples/lob-table-operations.html Alternatively, you might pass the table to a code block of a language that understands tables, such as an R data frame, and use that language to retrieve values by name. hth, Tom -- Thomas S. Dye http://www.tsdye.com
Re: [O] How to pass named table reference in source block variable
Thomas S. Dye tsd at tsdye.com writes: Perhaps this can help: http://orgmode.org/worg/org-contrib/babel/examples/lob-table- operations.html Alternatively, you might pass the table to a code block of a language that understands tables, such as an R data frame, and use that language to retrieve values by name. hth, Tom Thank you for the link, I'll check it but seems that it won't solve the problem. But anyway, I found a workaround that doesn't involve to insert table reference. It's a pity that I am so bad at Lisp because I feel this feature wouldn't be too complicated to code, especially if the reference mechanism is already implemented. Thank you again! Cheers, Roland.
Re: [O] How to pass named table reference in source block variable
Roland Donat roland.do...@gmail.com writes: Perhaps this can help: http://orgmode.org/worg/org-contrib/babel/examples/lob-table- operations.html Alternatively, you might pass the table to a code block of a language that understands tables, such as an R data frame, and use that language to retrieve values by name. hth, Tom Thank you for the link, I'll check it but seems that it won't solve the problem. But anyway, I found a workaround that doesn't involve to insert table reference. What is the workaround? All the best, Tom -- Thomas S. Dye http://www.tsdye.com
[O] How to pass named table reference in source block variable
Hello, I have the following table : #+TBLNAME: T | | x | 1 | | ^ | | varx | And I would like to use the reference T$var_x (=1) as input in a source block variable. For example, I would have expected the following behavior for this source code : #+begin_src python :var x=T$varx :return x x #+end_src #+RESULTS: : 1 But instead, I get the emacs message : org-babel-ref-resolve: Reference 'T$varx' not found in this buffer Any idea to produce the desired result would be much appreciated! Thanks you in advance. Roland.
Re: [O] How to pass named table reference in source block variable
Roland Donat roland.do...@gmail.com writes: Hello, I have the following table : #+TBLNAME: T | | x | 1 | | ^ | | varx | And I would like to use the reference T$var_x (=1) as input in a source block variable. For example, I would have expected the following behavior for this source code : #+begin_src python :var x=T$varx :return x x #+end_src #+RESULTS: : 1 But instead, I get the emacs message : org-babel-ref-resolve: Reference 'T$varx' not found in this buffer Any idea to produce the desired result would be much appreciated! Thanks you in advance. Roland. This does the job in Emacs Lisp: #+TBLNAME: T | | x | 1 | | ^ | | varx | #+begin_src emacs-lisp :var x=T[0,-1] x #+end_src #+results: : 1 -- cheers, Thorsten
Re: [O] How to pass named table reference in source block variable
Thorsten Jolitz tjol...@gmail.com writes: Roland Donat roland.do...@gmail.com writes: Hello, I have the following table : #+TBLNAME: T This does the job in Emacs Lisp: #+TBLNAME: T | | x | 1 | | ^ | | varx | #+begin_src emacs-lisp :var x=T[0,-1] x #+end_src #+results: : 1 Nit: I believe #+TBLNAME is obsolete/deprecated/frowned upon - use #+name going forward. -- Nick