From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Leha Subject: Re: Selective export of Babel code blocks Date: Mon, 18 Jun 2012 20:06:54 +0200 Message-ID: <877gv4bikh.fsf@med.uni-goettingen.de> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:37366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SggN0-0000bn-9o for emacs-orgmode@gnu.org; Mon, 18 Jun 2012 14:08:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SggMy-0004bo-2C for emacs-orgmode@gnu.org; Mon, 18 Jun 2012 14:08:09 -0400 Received: from plane.gmane.org ([80.91.229.3]:59320) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SggMx-0004bd-Nt for emacs-orgmode@gnu.org; Mon, 18 Jun 2012 14:08:07 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SggMv-00073m-85 for emacs-orgmode@gnu.org; Mon, 18 Jun 2012 20:08:05 +0200 Received: from vpn-2144.gwdg.de ([134.76.2.144]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 18 Jun 2012 20:08:05 +0200 Received: from andreas.leha by vpn-2144.gwdg.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 18 Jun 2012 20:08:05 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org John Hendy writes: > On Mon, Jun 18, 2012 at 12:16 PM, suvayu ali > wrote: >> Hi Thomas, >> >> On Mon, Jun 18, 2012 at 7:11 PM, Thomas S. Dye 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" <> <> <> #+end_src Or even more org-mode-ish #+begin_src R :noweb yes :var fn="export-file-name.tex" <> <> <> #+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: > > <> to define my export file > Some sort of R code doing something. > <> 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 < "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.