From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: How to pass named table reference in source block variable Date: Thu, 08 Aug 2013 09:10:19 -0600 Message-ID: <87ob98b4mc.fsf@gmail.com> References: <87mwou1mu6.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7Rtk-0006of-MM for emacs-orgmode@gnu.org; Thu, 08 Aug 2013 11:13:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V7Rte-0007XO-T7 for emacs-orgmode@gnu.org; Thu, 08 Aug 2013 11:13:08 -0400 Received: from mail-pb0-x22f.google.com ([2607:f8b0:400e:c01::22f]:58765) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7Rte-0007Wz-Lo for emacs-orgmode@gnu.org; Thu, 08 Aug 2013 11:13:02 -0400 Received: by mail-pb0-f47.google.com with SMTP id rr4so3371476pbb.6 for ; Thu, 08 Aug 2013 08:13:01 -0700 (PDT) In-Reply-To: (Roland Donat's message of "Thu, 8 Aug 2013 07:55:50 +0000 (UTC)") 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: Roland Donat Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Roland Donat writes: > Thomas S. Dye tsdye.com> writes: > >> >> Roland Donat 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. --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=key-value.org 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 <