emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rainer M Krug <r.m.krug@gmail.com>
To: "Thomas S. Dye" <tsd@tsdye.com>
Cc: Org-mode <emacs-orgmode@gnu.org>, "Charles C. Berry" <ccberry@ucsd.edu>
Subject: Re: ob-R, problem with try/catch
Date: Thu, 23 Apr 2015 18:20:10 +0200	[thread overview]
Message-ID: <0A7B5324-A080-493C-AFAA-B597B3DD539E@gmail.com> (raw)
In-Reply-To: <m2egnadeor.fsf@tsdye.com>



Envoyé de mon iPhone

> Le 23 avr. 2015 à 17:53, Thomas S. Dye <tsd@tsdye.com> a écrit :
> 
> Aloha Rainer,
> 

Hi Thomas,

> Rainer M Krug <r.m.krug@gmail.com> writes:
> 
>>>> After eaa3a761dae, I get an error and an empty output file.
>>> 
>>> That commit introduced a tryCatch() wrapper for graphics results.
>>> 
>>> You probably know that ggplot (or ggplot2) relies on printing of
>>> objects to produce graphics (see R-FAQ 7.22).
>>> 
>>> tryCatch(expr,...) evaluates expr and returns its value, which is
>>> `rm(g)' in your case. But `rm(g)' is not autoprinted, and you get an
>>> empty file.
>> 
>> I am not in front of my computer but there must be more, as even
>> before the commit there should have been empty file for exactly the
>> same reason. Also, the error is strange. Could you send a small
>> reproducable example, so that we can see which error you get? Because
>> if you get an error and an empty file, an error must be in the
>> tryCatcb block.
> 
> I'm picking up a project that I last worked on in 2013.  I was under the
> impression that the source code blocks were working at that time, but I
> guess it is possible that I added the rm() statements after the code
> blocks were working and didn't realize that the addition broke them.

The rm() did not break anything. The behavior that if you want to have a ggplot (and e.g. Lattice as well) in a pdf/png/... You have to use print() is standard R behavior and was the same before. This question question comes up from time to time on the R list as well. And I don't think this can be easily be dealt with in org, as it is standard R. 


>  I
> haven't looked too deeply into the problem, but just assumed that the
> session expressed in the source code block behaved as if it were entered
> at the R prompt.

It does - only that you wrap you code in pdf() ... dev.off() to get the output in a file. 

> 
> In the R session, I see this, which I initially thought was an error:
> 
>> png(filename="r/buck-shoulder-hist.png",width=400,height=300); tryCatch({
> b <- ggplot(x, aes(x=((thickness_shoulder * 100) / mapply(max, width_shoulder_front, width_shoulder_back))))
> b + geom_histogram(aes(y=..density..))  + geom_density(weight=2) +
> xlab("Buck's Shoulder Index") + facet_wrap(~ turner)
> rm(b)
> },error=function(e){plot(x=-1:1, y=-1:1, type='n', xlab='', ylab='', axes=FALSE); text(x=0, y=0, labels=e$message, col='red'); paste('ERROR', e$message, sep=' : ')}); dev.off()
> 'org_babel_R_eoe'
> + . + null device 
>          1 
> 

Nope - this is no error, but simply the code evaluated. An error would be shown in the resulting graph. 

> hth,

Yes it does,

Cheers,

Rained

> Tom
> 
> -- 
> Thomas S. Dye
> http://www.tsdye.com

  reply	other threads:[~2015-04-23 16:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-22 22:03 ob-R, problem with try/catch Thomas S. Dye
2015-04-23  2:23 ` Charles C. Berry
2015-04-23  5:40   ` Rainer M Krug
2015-04-23 15:53     ` Thomas S. Dye
2015-04-23 16:20       ` Rainer M Krug [this message]
2015-04-23 16:42         ` Aaron Ecay
2015-04-23 16:13     ` Charles C. Berry
2015-04-23 16:29       ` Rainer M Krug
2015-04-23 17:11         ` Thomas S. Dye
2015-04-23 22:39           ` Aaron Ecay
2015-04-23 23:36             ` Thomas S. Dye
2015-04-26 12:49         ` Nicolas Goaziou
2015-04-26 17:11           ` Charles C. Berry
2015-04-26 17:28             ` Nicolas Goaziou
2015-05-04  8:35             ` Rainer M Krug
2015-05-04 19:03               ` Nicolas Goaziou
2015-04-23  6:35   ` Thomas S. Dye

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=0A7B5324-A080-493C-AFAA-B597B3DD539E@gmail.com \
    --to=r.m.krug@gmail.com \
    --cc=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=tsd@tsdye.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 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).