From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Leha Subject: Re: [babel] noweb reference with default values Date: Thu, 17 Dec 2015 11:47:30 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9X2C-0004rm-Sc for emacs-orgmode@gnu.org; Thu, 17 Dec 2015 06:47:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9X28-0001cq-If for emacs-orgmode@gnu.org; Thu, 17 Dec 2015 06:47:48 -0500 Received: from plane.gmane.org ([80.91.229.3]:44129) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9X28-0001cl-CO for emacs-orgmode@gnu.org; Thu, 17 Dec 2015 06:47:44 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1a9X21-0001fb-Dj for emacs-orgmode@gnu.org; Thu, 17 Dec 2015 12:47:38 +0100 Received: from 193.63.221.204 ([193.63.221.204]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 17 Dec 2015 12:47:37 +0100 Received: from andreas.leha by 193.63.221.204 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 17 Dec 2015 12:47:37 +0100 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: emacs-orgmode@gnu.org Hi all, Andreas Leha writes: > Hi Chuck, > > "Charles C. Berry" writes: >> On Mon, 14 Dec 2015, Andreas Leha wrote: >> >>> Hi all, >>> >>> I'd like to hear your ideas on how to include noweb references to code >>> blocks in a way that the default values are used as parameter values. >>> >>> Here is a little example: >>> >>> #+PROPERTY: header-args:R :session *testR* >>> >>> The background is that I like to use Org mode table to record small data. >>> >>> #+name: datatable >>> | A | B | >>> |---+----| >>> | 1 | 10 | >>> | 2 | 20 | >>> >>> Usually I want to pre-process and/or convert such data. >>> >>> #+name: read_datatable >>> #+header: :var datatable=datatable >>> #+begin_src R :results none >>> datatable$B <- 10 * datatable$B >>> #+end_src >>> >>> Later I would like to use that data in larger (R-) code blocks. I'd >>> like such code blocks to DWIM: >>> >>> #+name: some_code >>> #+begin_src R :noweb yes :results graphics :file testplot.png >>> <> >>> plot(datatable$A, datatable$B) >>> #+end_src >>> >>> But they do not: They are not stand alone and do not execute -- unless I >>> executed `read_datatable' manually/by chance upfront. >> >> Try this: >> >> #+name: read_datatable >> #+header: :var datatable=datatable >> >> #+begin_src R :results value :colnames yes >> datatable$B <- 10 * datatable$B >> datatable >> #+end_src >> >> #+name: some_code >> #+HEADER: :var datatable=read_datatable() >> >> #+begin_src R :noweb yes :results graphics :file testplot.png >> plot(datatable$A, datatable$B) >> #+end_src >> > > Thanks! I am aware of that possibility. Should have posted a more > involved example. This works if I only return a table. Or something > else, that can be passed through Org. But it fails for instance if the > result is a function (or more functions...). > In case anyone is interested. I came up with a quite simple code block that does what I want: --8<---------------cut here---------------start------------->8--- #+name: org_exec #+header: :var srcblock="" #+begin_src emacs-lisp :results silent (save-excursion (org-babel-goto-named-src-block srcblock) (org-babel-execute-src-block) ) (concat srcblock " executed") #+end_src --8<---------------cut here---------------end--------------->8--- Now, I can do --8<---------------cut here---------------start------------->8--- #+name: some_code #+begin_src R :session *testR* :noweb yes :results graphics :file testplot.png <> plot(datatable$A, datatable$B) #+end_src --8<---------------cut here---------------end--------------->8--- The remaining downside is that I have to take care of running things in the correct session. Best, Andreas PS: complete example: --8<---------------cut here---------------start------------->8--- * Org #+name: org_exec #+header: :var srcblock="" #+begin_src emacs-lisp :results silent (save-excursion (org-babel-goto-named-src-block srcblock) (org-babel-execute-src-block) ) (concat "\"" srcblock " executed" "\"") #+end_src * Data #+name: datatable | A | B | |---+----| | 1 | 10 | | 2 | 20 | #+name: read_datatable #+header: :var datatable=datatable #+begin_src R :session *testR* :results value :colnames yes datatable$B <- 10 * datatable$B datatable #+end_src #+results: read_datatable | A | B | |---+-----| | 1 | 100 | | 2 | 200 | * Analysis #+name: some_code #+begin_src R :session *testR* :noweb yes :results graphics :file testplot.png <> plot(datatable$A, datatable$B) #+end_src #+results: some_code [[file:testplot.png]] --8<---------------cut here---------------end--------------->8---