From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: Tangle including code generating graphics for :results graphics Date: Thu, 24 Sep 2015 11:03:15 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf2R7-0007V5-Bf for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 05:03:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zf2R2-0000mp-9K for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 05:03:29 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:35136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf2R2-0000lz-1M for emacs-orgmode@gnu.org; Thu, 24 Sep 2015 05:03:24 -0400 Received: by wicge5 with SMTP id ge5so242315058wic.0 for ; Thu, 24 Sep 2015 02:03:23 -0700 (PDT) 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: Andreas Leha Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Andreas Leha writes: > Hi Rainer, > > Rainer M Krug writes: >> Hi >> >> Is it possible to tangle an R code block including the code which is >> generating the graphs when using =3D:results graphics=3D ? >> >> I would like to tangle these code blocks generating the graphs as I >> would like to have a script which I can use to easily update all graphs >> when the simulated input data is updated. I have this for the actual >> analysis which works perfectly, but would like to have the same for the >> graphs. At the same time, I like the clarity of specifying :width and >> :height and other parameter for the plotting as header arguments. >> >> I have >> >> ,---- >> | :PROPERTIES: >> | :header-args+: :prologue "env <- fitBFGS; attach(env)" >> | :header-args+: :epilogue "detach(env); rm(env)" >> | :END: >> `---- >> >> and this is tangled perfectly - but obviously not the code for >> plotting. Is there an argument / setting to enable this? >> >> Thanks, >> >> Rainer > > That is a very relevant question and I'd be interested in the answer as > well. But I am not aware of any support by Org mode for this. > > I guess calling `org-babel-expand-src-block' prior to tangling would > answer your needs? I don't think so - as this is doing the same as C-c. The graphics code is only added in the call of org-babel-execute:R so some refactoring would be necessary.=20 In org-babel-execute:R there is the following code: #+begin_src emacs-lisp=20 (full-body (let ((inside (list (org-babel-expand-body:R body params graphics-file)))) (mapconcat 'identity (if graphics-file (append (list (org-babel-R-construct-graphics-device-call graphics-file params)) inside (list "},error=3Dfunction(e){plot(x=3D-1:1, y=3D-1:1, type=3D'n', = xlab=3D'', ylab=3D'', axes=3DFALSE); text(x=3D0, y=3D0, labels=3De$message,= col=3D'red'); paste('ERROR', e$message, sep=3D' : ')}); dev.off()")) inside) "\n"))) #+end_src If this expansion is moved into org-babel-expand-body:R, it should work and *always* expand the graphics code (as org-babel-expand-body:R adds the :epilogue and :prologue). Then one would just need a new header argument and it should work. > > This would be desirable not only for plotting code blocks, also data > passed to code block is 'lost' during tangling. Yes - debugging the whole process of evaluation would also be much easier. > > I think it would be good to have a source block header argument, say > `:tangleexpanded', controlling such functionality. > > WDYT? Yes - that would be an ideal solution. But expanded is already used in a different context (noweb), so something like :tangleaseval would make sense, making clear that the code is tangled as it would be evaluated. Unfortunately, I have no time for looking into this at the moment. But it should be possible without to much hassle. Thanks, Rainer > > Regards, > Andreas > > =2D-=20 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,= UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer@krugs.de Skype: RMkrug PGP: 0x0F52F982 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBCAAGBQJWA7xXAAoJENvXNx4PUvmCTUQIALEo/IzxX/e9TwFuk+cnh2pV y6/WVBa1NBGPwqVmLGEDUaeZznWRiIVOeCJfMa+VtjNYgtrZnUE48/J1XOGpHYq/ jcdaGEGSrnfMkjhGxXk7t2IzqFaFAjq81CMSJjJMBRGBHnM9SvK295SyRdm4gEuY Tm94QhgdJ5gO+5Kb0bgaZADPLWZbcQujbmSoMG+l83HmIBeavepF8zBdT+H70iww IwS5p55ubpvB4zIH71Qh0uPLVAlC0fryEzNPNO/osD0b3PB2QpcXoXTSUFMK8f7i 52077qRLA810B+sVNro/F9ZzQlIy2iKKtDEbJzA3ZpdXbCuyO1XlK0i/rZzsXww= =gvLw -----END PGP SIGNATURE----- --=-=-=--