From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Calling org babel to each row in a table Date: Sun, 30 Jun 2013 17:33:14 -0600 Message-ID: <87txkfjgfo.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtRaz-00074u-Sv for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 20:03:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UtRay-0001ZG-QA for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 20:03:53 -0400 Received: from mail-pd0-x22a.google.com ([2607:f8b0:400e:c02::22a]:38692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtRay-0001Z0-Ku for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 20:03:52 -0400 Received: by mail-pd0-f170.google.com with SMTP id x11so2165453pdj.15 for ; Sun, 30 Jun 2013 17:03:51 -0700 (PDT) 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: Joe Bogner Cc: emacs-orgmode@gnu.org Joe Bogner writes: > I often need to transform a table or list of values into a block of text. > For example, if I have a list of 4 files that I want to generate a SQL > script for. > > After hunting around, this is the best I came up with: > > #+name: table > | File | > | a | > | b | > | c | > | d | > > #+name: template > #+begin_src org :results verbatim :var name="abc" > DROP TABLE $name > > CREATE TABLE $name (name varchar(100)) > > BULK INSERT $name FROM '\\1.1.1.1\$name.txt' ... > #+end_src > > #+name: apply-template > #+begin_src emacs-lisp :results silent :var table=() > (let (result-table) > (dolist (line (cdr table)) > (setq result-table (cons (concat "#+call: template(\"" (car line) > "\") :results raw drawer") result-table))) > (mapconcat 'identity (nreverse result-table) "\n")) > #+end_src > > #+call: apply-template(table) :results org :exports both > > #+RESULTS: apply-template(table):results org :exports both > #+BEGIN_SRC org > #+END_SRC > > > > Is there a more straightforward method to apply this type of > transformation? Ideally I would skip the emacs-lisp block and use some > syntax to apply a org-babel block for each row in a table. > > > It sounded similar to this: > http://thread.gmane.org/gmane.emacs.orgmode/69326/focus=69340*, *but that > didn't have a full example for me to build off of > > Is there a more straightforward to accomplish this transformation? > Hi Joe, There is no way to map a code block over the rows of a table. You could use the `sbe' macro and a spreadsheet formula to call a code block on multiple table cells, but the results would be inserted back into the table. | A | -->A<-- | | B | -->B<-- | | eric | -->eric<-- | | schulte | -->schulte<-- | #+TBLFM: $2='(sbe foo (in $$1)) #+name: foo #+begin_src emacs-lisp :var in="foo" (format "-->%s<--" in) #+end_src Possibly you could use the sbe macro to simplify the elisp code block in your example. Best, > > Thanks, > Joe -- Eric Schulte http://cs.unm.edu/~eschulte