all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Rainer M Krug <Rainer@krugs.de>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: Andreas Leha <andreas.leha@med.uni-goettingen.de>, emacs-orgmode@gnu.org
Subject: Re: [babel] suggestion: wrap creation of graphics into try() block
Date: Mon, 20 Jan 2014 18:02:29 +0100	[thread overview]
Message-ID: <52DD56A5.4080901@krugs.de> (raw)
In-Reply-To: <87txcyy8dm.fsf@gmail.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



On 01/20/14, 16:28 , Eric Schulte wrote:
> Rainer M Krug <Rainer@krugs.de> writes:
> 
>> On 01/20/14, 15:00 , Andreas Leha wrote:
>>> Rainer M Krug <Rainer@krugs.de> writes:
>>> 
>>>> Hi
>>>> 
>>>> I have two suggestions which are liked to each other. They
>>>> are based on R code blocks, but the should be useful for
>>>> other languages as well.
>>>> 
>>>> I have a document in which I use :session for creating R
>>>> graphs. These look like:
>>>> 
>>>> #+begin_src R :file Correlation_1.pdf :results graphics
>>>> IFN.mean <- load.IFN.mean() grid <-
>>>> load.grid.CASTANEA.average() image(IFN.mean) #+end_src
>>>> 
>>>> Everything works fine, unless there is an error in one
>>>> graph.
>>>> 
>>>> In this case, the device remains open, which leaves open
>>>> devices at the end of the export of the document.
>>> 
>>> I experience the same problem.  And would love to see that 
>>> addressed.
>> 
>> Just checked in the code from ob-R.el, and it should not be to
>> difficult:
>> 
>> The functions org-babel-R-construct-graphics-device-call and 
>> org-babel-expand-body:R
>> 
>> would be affected.
>> 
>> I changed :
>> 
>> 
>> 
>> ... Trying it out ...
>> 
>> This seems to be working - I just changed it and it closes the
>> device. But further tests are needed. I will leave it to see if
>> anything unexpected happens.
>> 
> 
> Sounds great.  When you're confident that this is working please
> submit a patch and I'll be happy to apply it.

I will check it a little bit longer and see that I can display the
error message in the dummy graphic. Should have it by tomorrow.

I'll send you the patch then.

This is the first time I really work with patches - I assume "git
diff" will give me the patch you need?

Cheers,

Rainer

> 
> Thanks,
> 
>> 
>> If somebody could look if this makes sense? (defun
>> org-babel-expand-body:R (body params &optional graphics-file) 
>> "Expand BODY according to PARAMS, return the expanded body." (let
>> ((graphics-file (or graphics-file
>> (org-babel-R-graphical-output-file params)))) (mapconcat 
>> #'identity (let ((inside (append (when (cdr (assoc :prologue
>> params)) (list (cdr (assoc :prologue params)))) 
>> (org-babel-variable-assignments:R params) (list body) (when (cdr
>> (assoc :epilogue params)) (list (cdr (assoc :epilogue
>> params))))))) (if graphics-file (append (list
>> (org-babel-R-construct-graphics-device-call graphics-file
>> params)) inside ;; my edits (list "},error=function(e){plot(-1:1,
>> -1:1, type='n'); text(0,0,'DUMMY')}); dev.off()")) inside)) ;;
>> end "\n")))
>> 
>> 
>> 
>> and
>> 
>> (format "%s(%s=\"%s\"%s%s%s); tryCatch({" device filearg out-file
>> args (if extra-args "," "") (or extra-args ""))))
>> 
>> in org-babel-R-construct-graphics-device-call
>> 
>> It is working with the Dummy.
>> 
>> Could somebody please check if this is working?
>> 
>> I am leaving my changes and will see during my work if it is
>> fine.
>> 
>> Cheers,
>> 
>> Rainer
>> 
>> 
>>> 
>>>> 
>>>> If the code block which should create the graph would be
>>>> wrapped into a try() block, so that it would look like the
>>>> following:
>>>> 
>>>> try( { pdf("./Correlation_1.pdf") IFN.mean <-
>>>> load.IFN.mean() grid <- load.grid.CASTANEA.average()
>>>> image(IFN.mean) } ) dev.off()
>>>> 
>>>> The device would be closed even if an error occurred during
>>>> the execution of the code.
>>>> 
>>>> But still, when  exporting to pdf, the call to pdflatex fails
>>>> as only a empty pdf is available. So it becomes necessary to
>>>> go through the pdf log to identify the graphs which failed.
>>>> 
>>>> In this case it would be useful, to have a placeholder grah
>>>> in the final pdf, so that one can see which graphs did not
>>>> work.
>>>> 
>>>> In addition, this could be used as placeholders (well - they
>>>> are placeholders) for to be created graphs, while the text
>>>> has already been written.
>>>> 
>>>> So my second suggestion would be to include a placeholder
>>>> image, which would be used if the generation of the actual
>>>> graph fails. It would be great (but not necessary) if the
>>>> actual error message would be in the image.
>>> 
>>> Such an place holder image would be great, indeed.
>>> 
>>> 
>>> Thanks for bringing this up!
>>> 
>>> Regards, Andreas
>>> 
>>> 
>> 
>> -- 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
> 

- -- 
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJS3ValAAoJENvXNx4PUvmClnYIAJiHXrgXaQoZuyvIS8kpW9QR
iBJUirAZK+49CQEfwoFulWwr46jEqyAxX5eJEUAe1jw6plNRkS7qvuxYWqmydDII
m588aiQ7sB2jo72LF/Lo/qv1niYaWjBRH6gTQ8aN3I4kj2ZLOOSD3dDjkEZsoLjf
QpmQaAHnHwcBZ3+OLczbtjgCW/a8VrYK1LlVdZ1mNu4i151PMurdvZyeZ9Mj++aZ
wpT/KybjFkBtKTm/bEUtcV3ZfwG9BW3xhXZBTIDtSxq8EzWBg92LrCEYq8jzJElV
LU+3A3l6NxuD8WM92CsScNkiutnVGmhrvxFopLD13WbWpMIDuob7kN5lrQql2Uc=
=lHhr
-----END PGP SIGNATURE-----

  reply	other threads:[~2014-01-20 17:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-20 13:36 [babel] suggestion: wrap creation of graphics into try() block Rainer M Krug
2014-01-20 14:00 ` Andreas Leha
2014-01-20 15:13   ` Rainer M Krug
2014-01-20 15:28     ` Eric Schulte
2014-01-20 17:02       ` Rainer M Krug [this message]
2014-01-20 18:38         ` Eric Schulte
2014-01-21  9:52           ` Rainer M Krug
2014-01-21 10:03             ` Andreas Leha
2014-01-21 10:43               ` :draft header argument for source block evaluation - WAS: " Rainer M Krug
2014-01-26 18:07             ` Eric Schulte
2014-01-27  9:10               ` Rainer M Krug

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

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

  git send-email \
    --in-reply-to=52DD56A5.4080901@krugs.de \
    --to=rainer@krugs.de \
    --cc=andreas.leha@med.uni-goettingen.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.