emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] [babel] noweb reference with default values


From: Andreas Leha
Subject: Re: [O] [babel] noweb reference with default values
Date: Mon, 14 Dec 2015 22:18:20 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (darwin)

Hi Chuck,

"Charles C. Berry" <address@hidden> 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
>>  <<read_datatable>>
>>  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...).

Regards,
Andreas




reply via email to

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