[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] How to pass named table reference in source block variable

From: Eric Schulte
Subject: Re: [O] How to pass named table reference in source block variable
Date: Thu, 08 Aug 2013 09:10:19 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Roland Donat <address@hidden> 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

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}"

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.

: Pulling the data from the above table we find
: that foo is 1 and baz is 3.

Eric Schulte
PGP: 0x614CA05D

reply via email to

[Prev in Thread] Current Thread [Next in Thread]