emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Selective export of Babel code blocks


From: Thomas S. Dye
Subject: Re: [O] Selective export of Babel code blocks
Date: Mon, 18 Jun 2012 09:05:46 -1000

suvayu ali <address@hidden> writes:

> Hi Thomas,
>
> On Mon, Jun 18, 2012 at 7:11 PM, Thomas S. Dye <address@hidden> wrote:
>> #+CALL: clean-up() :exports none
>>
>> This way, the original code block will be exported and subsequent calls
>> should not be.
>
> I think John's use case requires other code blocks "using" the common
> code block. Can a "CALL" be done from inside a codeblock?
>
> That said, your post gave me an idea; how about defining a function in
> the first code block and then using that in the other blocks. This would
> require the session feature of course. :)
Hi Suvayu,

Yes, there are several ways to accomplish John's goal, depending on how
he wants to structure the R code and whether or not he wants to preserve
state with one or more sessions.

I don't think it is possible to use #+CALL: inside a code block.  For
that, there is noweb syntax.  So, for John's recent code, this should
work with or without sessions:

#+name: preamble
#+begin_src R
   tikzDevice("export-file-name.tex")
#+end_src

#+begin_src R :noweb yes
   <<preamble>>
   ggplot(data, aex(x=x, y=y)) + geom_point()
#+end_src


The :noweb header argument can take several values to control when these
noweb references are expanded.  Many of these don't show in the Org-mode
manual on Worg.  Here they are in org.texi:

The @code{:noweb} header argument controls expansion of ``noweb'' syntax
references (see @ref{Noweb reference syntax}) when the code block is
evaluated, tangled, or exported.  The @code{:noweb} header argument can have
one of the five values: @code{no}, @code{yes}, @code{tangle}, or
@code{no-export} @code{strip-export}.

@itemize @bullet
@item @code{no}
The default.  ``Noweb'' syntax references in the body of the code block will
not be expanded before the code block is evaluated, tangled or exported.
@item @code{yes}
``Noweb'' syntax references in the body of the code block will be
expanded before the code block is evaluated, tangled or exported.
@item @code{tangle}
``Noweb'' syntax references in the body of the code block will be expanded
before the code block is tangled.  However, ``noweb'' syntax references will
not be expanded when the code block is evaluated or exported.
@item @code{no-export}
``Noweb'' syntax references in the body of the code block will be expanded
before the block is evaluated or tangled.  However, ``noweb'' syntax
references will not be expanded when the code block is exported.
@item @code{strip-export}
``Noweb'' syntax references in the body of the code block will be expanded
before the block is evaluated or tangled.  However, ``noweb'' syntax
references will not be removed when the code block is exported.
@item @code{eval}
``Noweb'' syntax references in the body of the code block will only be
expanded before the block is evaluated.
@end itemize

So, John might be satisfied with something like this:

#+begin_src R :noweb no-export
   <<preamble>>
   ggplot(data, aex(x=x, y=y)) + geom_point()
#+end_src

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com



reply via email to

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