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: Andreas Leha
Subject: Re: [O] Selective export of Babel code blocks
Date: Mon, 18 Jun 2012 20:06:54 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

John Hendy <address@hidden> writes:

> 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
>

Not sure, whether I got you correctly.  Why do you need pdf, if you go
along the LaTeX route?  But how about sth along

#+name: preamble
#+begin_src: R
  tikzDevice(fn)
#+end_src

#+name: postamble
#+begin_src: R
  dev.off()
  tools::texi2pdf(fn)
#+end_src


#+name: statistics
#+begin_src R
  ggplot(data, aex(x=x, y=y)) + geom_point()
#+end_src


#+begin_src R :noweb yes
  fn <- "export-file-name.tex"
  <<preamble>>
  <<statistics>>
  <<postamble>>
#+end_src


Or even more org-mode-ish

#+begin_src R :noweb yes :var fn="export-file-name.tex"
  <<preamble>>
  <<statistics>>
  <<postamble>>
#+end_src

Is that closer to what you want?


BTW:  If you are not aware of that, you can have the source block return
tikz code without the manual "tikz("dtrn")"

If you combine that with a general tikz2pdf converter, you could do (untested):

#+name: tikz2pdf
#+begin_src R :var fn="foo.tex"
  tools::texi2pdf(fn)
#+end_src

#+name: dotheplot
#+begin_src R :exports code :noweb yes :results graphics :file "export-file.tex"
  ggplot(data, aex(x=x, y=y)) + geom_point()
#+end_src

#+call tikz2pdf[:var fn=dotheplot()]() :exports results :results file


Regards,
Andreas

> 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.




reply via email to

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