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:29:54 +0200 Message-ID: <0A59ABA8-865B-44CE-823A-0CC168983981@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]:59250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlK0r-0003LH-Gw for emacs-orgmode@gnu.org; Thu, 23 Apr 2015 12:30:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YlK0k-0006L6-JU for emacs-orgmode@gnu.org; Thu, 23 Apr 2015 12:30:05 -0400 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]:34908) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlK0k-0006Ku-Bd for emacs-orgmode@gnu.org; Thu, 23 Apr 2015 12:29:58 -0400 Received: by widdi4 with SMTP id di4so222402987wid.0 for ; Thu, 23 Apr 2015 09:29:57 -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: "Charles C. Berry" Cc: Org-mode , "Thomas S. Dye" Envoy=C3=A9 de mon iPhone > Le 23 avr. 2015 =C3=A0 18:13, Charles C. Berry a =C3=A9= crit : >=20 >> On Wed, 22 Apr 2015, Rainer M Krug wrote: >>=20 >>=20 >>=20 >> Envoy=C3=A9 de mon iPhone >>=20 >>>> Le 23 avr. 2015 =C3=A0 04:23, Charles C. Berry a =C3= =A9crit : >>>>=20 >>>> On Wed, 22 Apr 2015, Thomas S. Dye wrote: >>>>=20 >>>> Aloha all, >>>>=20 >>>> Prior to eaa3a761dae, when working in a session, I was able to run this= >>>> R source code block without problems: >>>>=20 >>>> ,----------------------------------------- >>>> | #+header: :file r/adze_wt_log.pdf >>>> | #+header: :results output graphics >>>> | #+header: :width 4 :height 3 >>>> | #+begin_src R >>>> | g <- ggplot(x, aes(x =3D weight)) >>>> | g + geom_histogram(aes(y=3D..density..)) >>>=20 >>> ## Try this: >>>=20 >>> print( g + geom_histogram(aes(y=3D..density..)) ) # before rm(g). >>>=20 >>>=20 >>>> | rm(g) >>>> | #+end_src >>>> `----------------------------------------- >>>>=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 t= he commit there should have been empty file for exactly the same reason. >=20 > `:results output' will return the autoprinted values. Without tryCatch it w= orks. >=20 >=20 >> Also, the error is strange. Could you send a small reproducable example, s= o that we can see which error you get? Because if you get an error and an em= pty file, an error must be in the tryCatcb block. >=20 > Here are two blocks that differ in using tryCatch. The first produces an e= mpty, malformed pdf. The second produces a valid pdf. If you comment out the= `invisible()' line in the first, then both will produce similar valid pdf's= . >=20 > #+header: :file nada.pdf > #+header: :results output graphics > #+header: :width 4 :height 3 > #+begin_src R > require(ggplot2) > df <- > data.frame(gp =3D factor(rep(letters[1:3], each =3D 10)), > y =3D rnorm(30)) > ggplot(df, aes(x =3D gp, y =3D y)) + geom_point() > invisible() > #+end_src >=20 >=20 > #+BEGIN_SRC R :results output > require(ggplot2) > pdf(file=3D"aok.pdf",width=3D4,height=3D3) > df <- > data.frame(gp =3D factor(rep(letters[1:3], each =3D 10)), > y =3D rnorm(30)) > ggplot(df, aes(x =3D gp, y =3D y)) + geom_point() > invisible() > dev.off() > #+END_SRC >=20 >=20 Sorry I overlooked the :results output graphic header.=20 This combination is, as far as I can see (holiday, sun, no notebook, org or R= ) not recommended as it will lead to invalid files.=20 Should it actually be valid? I would say these two options contradict each o= ther, as output returns the output from the session ( terminal ) which is no= t a graphic.=20 Possible a candidate for the new linting library for org, to mark it as an i= nvalid argument combination=20 Cheers,=20 Rainer >=20 > HTH, >=20 > Chuck