From: Eric Schulte <schulte.eric@gmail.com>
To: Roland Donat <roland.donat@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: How to pass named table reference in source block variable
Date: Thu, 08 Aug 2013 09:10:19 -0600 [thread overview]
Message-ID: <87ob98b4mc.fsf@gmail.com> (raw)
In-Reply-To: <loom.20130808T094956-187@post.gmane.org> (Roland Donat's message of "Thu, 8 Aug 2013 07:55:50 +0000 (UTC)")
[-- Attachment #1: Type: text/plain, Size: 1652 bytes --]
Roland Donat <roland.donat@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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: key-value.org --]
[-- Type: text/x-org, Size: 776 bytes --]
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.
[-- Attachment #3: Type: text/plain, Size: 71 bytes --]
Cheers,
--
Eric Schulte
http://cs.unm.edu/~eschulte
PGP: 0x614CA05D
next prev parent reply other threads:[~2013-08-08 15:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-06 21:31 How to pass named table reference in source block variable Roland Donat
2013-08-06 22:22 ` Thorsten Jolitz
2013-08-06 22:27 ` Nick Dokos
2013-08-07 8:28 ` Roland Donat
2013-08-07 15:29 ` Thomas S. Dye
2013-08-07 20:06 ` Roland Donat
2013-08-07 21:53 ` Thomas S. Dye
2013-08-08 7:55 ` Roland Donat
2013-08-08 15:10 ` Eric Schulte [this message]
2013-08-08 15:42 ` Roland Donat
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ob98b4mc.fsf@gmail.com \
--to=schulte.eric@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=roland.donat@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).