[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Selective export of Babel code blocks
From: |
John Hendy |
Subject: |
Re: [O] Selective export of Babel code blocks |
Date: |
Mon, 18 Jun 2012 12:31:38 -0500 |
On Mon, Jun 18, 2012 at 12:16 PM, suvayu ali
<address@hidden> wrote:
> 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?
>
I think Thomas' suggestion would work. Let me try one more time to
clarify what I'm doing:
----------
First, I need to define my output file name for R -> tikz code. No code export
#+name: preamble
#+begin_src R
tikzDevice("export-file-name.tex")
#+end_src
Now, I run my actual code, which executes statistics and generates a
plot. I want this code exported in the paper.
#+begin_src R
ggplot(data, aex(x=x, y=y)) + geom_point()
#+end_src
Now R is sitting there with a plot in the "buffer" (not sure the
proper name). To get it to dump the plot into the tex file, I need to
execute =dev.off()=. Then I have to convert the tikz .tex file into a
pdf for including in the report:
#+name: postamble
#+begin_src R
dev.off()
tools::texi2pdf("export-file-name.tex")
#+end_src
For the report I'll have many, many iterations of:
<<preamble>> to define my export file
Some sort of R code doing something.
<<postamble>> to create the export file and convert to pdf.
I obviously can't use the same file name over and over as I'll be
overwriting it. Thus, I need some way to set the file name in the
preamble (something like <<preamble(file-name =
"plot-of-a-vs-b.tex">>) and a way to tell the postamble which file to
convert to pdf (the same one I created in the preamble). This if this
noweb path is going to work, I need to be able to pass file name
arguments to tikzDevice() in the first block and tools::texi2pdf() in
the last.
Is that clearer? I tried to think of an analogous situation in gnuplot
where you need the same code block again and again, but with unique
names/vars passed, but couldn't.
If #+call is doing what I think it does, that definitely could work...
again, as long as I can tell the #+call argument which filenames to
use in the "master" code blocks.
> 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. :)
I have session feature enabled in my paper because all subsequent
blocks depend on the very first block where I load my data file. If I
didn't use session, I'd have to repeat that code again and again or
they wouldn't know what data I was accessing/plotting. Your proposal
is possible, but again, it's not entirely one "static" block -- it's a
block using the same exact functions but with different arguments
passed for the unique filenames of each plot.
Hopefully this makes sense!
Thanks for the input,
John
>
> --
> Suvayu
>
> Open source is the future. It sets us free.