emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Andreas Leha <andreas.leha@med.uni-goettingen.de>
To: emacs-orgmode@gnu.org
Subject: Re: Selective export of Babel code blocks
Date: Mon, 18 Jun 2012 20:06:54 +0200	[thread overview]
Message-ID: <877gv4bikh.fsf@med.uni-goettingen.de> (raw)
In-Reply-To: CA+M2ft_6tLrptz5r3t5Wpvm=PLMdBwwiDJShYNYDurMOQt-g2w@mail.gmail.com

John Hendy <jw.hendy@gmail.com> writes:

> On Mon, Jun 18, 2012 at 12:16 PM, suvayu ali
> <fatkasuvayu+linux@gmail.com> wrote:
>> Hi Thomas,
>>
>> On Mon, Jun 18, 2012 at 7:11 PM, Thomas S. Dye <tsd@tsdye.com> 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	other threads:[~2012-06-18 18:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-18 14:53 Selective export of Babel code blocks John Hendy
2012-06-18 16:08 ` suvayu ali
2012-06-18 16:50   ` John Hendy
2012-06-18 17:08     ` suvayu ali
2012-06-18 17:37       ` William LÉCHELLE
2012-06-18 17:11 ` Thomas S. Dye
2012-06-18 17:16   ` suvayu ali
2012-06-18 17:31     ` John Hendy
2012-06-18 18:06       ` Andreas Leha [this message]
2012-06-18 19:05     ` Thomas S. Dye
2012-06-19 12:55       ` suvayu ali
2012-06-19 13:36         ` John Hendy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877gv4bikh.fsf@med.uni-goettingen.de \
    --to=andreas.leha@med.uni-goettingen.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).