From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: ob-R, problem with try/catch Date: Thu, 23 Apr 2015 18:20:10 +0200 Message-ID: <0A7B5324-A080-493C-AFAA-B597B3DD539E@gmail.com> References: <83477C11-94B6-467B-8CD5-77976FE83C31@gmail.com> Mime-Version: 1.0 (1.0) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlJrP-000630-CR for emacs-orgmode@gnu.org; Thu, 23 Apr 2015 12:20:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YlJrK-0002Xn-8n for emacs-orgmode@gnu.org; Thu, 23 Apr 2015 12:20:19 -0400 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]:38459) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlJrK-0002Xj-1e for emacs-orgmode@gnu.org; Thu, 23 Apr 2015 12:20:14 -0400 Received: by wiun10 with SMTP id n10so98368966wiu.1 for ; Thu, 23 Apr 2015 09:20:13 -0700 (PDT) In-Reply-To: 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: "Thomas S. Dye" Cc: Org-mode , "Charles C. Berry" Envoy=C3=A9 de mon iPhone > Le 23 avr. 2015 =C3=A0 17:53, Thomas S. Dye a =C3=A9crit := >=20 > Aloha Rainer, >=20 Hi Thomas, > Rainer M Krug writes: >=20 >>>> After eaa3a761dae, I get an error and an empty output file. >>>=20 >>> That commit introduced a tryCatch() wrapper for graphics results. >>>=20 >>> You probably know that ggplot (or ggplot2) relies on printing of >>> objects to produce graphics (see R-FAQ 7.22). >>>=20 >>> 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. >>=20 >> 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. >=20 > 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 ggp= lot (and e.g. Lattice as well) in a pdf/png/... You have to use print() is s= tandard R behavior and was the same before. This question question comes up f= rom 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.=20 > 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 outp= ut in a file.=20 >=20 > In the R session, I see this, which I initially thought was an error: >=20 >> png(filename=3D"r/buck-shoulder-hist.png",width=3D400,height=3D300); tryC= atch({ > b <- ggplot(x, aes(x=3D((thickness_shoulder * 100) / mapply(max, width_sho= ulder_front, width_shoulder_back)))) > b + geom_histogram(aes(y=3D..density..)) + geom_density(weight=3D2) + > xlab("Buck's Shoulder Index") + facet_wrap(~ turner) > rm(b) > },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'); p= aste('ERROR', e$message, sep=3D' : ')}); dev.off() > 'org_babel_R_eoe' > + . + null device=20 > 1=20 >=20 Nope - this is no error, but simply the code evaluated. An error would be sh= own in the resulting graph.=20 > hth, Yes it does, Cheers, Rained > Tom >=20 > --=20 > Thomas S. Dye > http://www.tsdye.com