From: Rainer M Krug <r.m.krug@gmail.com>
To: "Charles C. Berry" <ccberry@ucsd.edu>
Cc: Org-mode <emacs-orgmode@gnu.org>, "Thomas S. Dye" <tsd@tsdye.com>
Subject: Re: ob-R, problem with try/catch
Date: Thu, 23 Apr 2015 18:29:54 +0200 [thread overview]
Message-ID: <0A59ABA8-865B-44CE-823A-0CC168983981@gmail.com> (raw)
In-Reply-To: <alpine.OSX.2.00.1504230825340.434@charles-berrys-macbook.local>
Envoyé de mon iPhone
> Le 23 avr. 2015 à 18:13, Charles C. Berry <ccberry@ucsd.edu> a écrit :
>
>> On Wed, 22 Apr 2015, Rainer M Krug wrote:
>>
>>
>>
>> Envoyé de mon iPhone
>>
>>>> Le 23 avr. 2015 à 04:23, Charles C. Berry <ccberry@ucsd.edu> a écrit :
>>>>
>>>> On Wed, 22 Apr 2015, Thomas S. Dye wrote:
>>>>
>>>> Aloha all,
>>>>
>>>> Prior to eaa3a761dae, when working in a session, I was able to run this
>>>> R source code block without problems:
>>>>
>>>> ,-----------------------------------------
>>>> | #+header: :file r/adze_wt_log.pdf
>>>> | #+header: :results output graphics
>>>> | #+header: :width 4 :height 3
>>>> | #+begin_src R
>>>> | g <- ggplot(x, aes(x = weight))
>>>> | g + geom_histogram(aes(y=..density..))
>>>
>>> ## Try this:
>>>
>>> print( g + geom_histogram(aes(y=..density..)) ) # before rm(g).
>>>
>>>
>>>> | rm(g)
>>>> | #+end_src
>>>> `-----------------------------------------
>>>>
>>>> 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.
>
> `:results output' will return the autoprinted values. Without tryCatch it works.
>
>
>> 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.
>
> Here are two blocks that differ in using tryCatch. The first produces an empty, 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.
>
> #+header: :file nada.pdf
> #+header: :results output graphics
> #+header: :width 4 :height 3
> #+begin_src R
> require(ggplot2)
> df <-
> data.frame(gp = factor(rep(letters[1:3], each = 10)),
> y = rnorm(30))
> ggplot(df, aes(x = gp, y = y)) + geom_point()
> invisible()
> #+end_src
>
>
> #+BEGIN_SRC R :results output
> require(ggplot2)
> pdf(file="aok.pdf",width=4,height=3)
> df <-
> data.frame(gp = factor(rep(letters[1:3], each = 10)),
> y = rnorm(30))
> ggplot(df, aes(x = gp, y = y)) + geom_point()
> invisible()
> dev.off()
> #+END_SRC
>
>
Sorry I overlooked the :results output graphic header.
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.
Should it actually be valid? I would say these two options contradict each other, as output returns the output from the session ( terminal ) which is not a graphic.
Possible a candidate for the new linting library for org, to mark it as an invalid argument combination
Cheers,
Rainer
>
> HTH,
>
> Chuck
next prev parent reply other threads:[~2015-04-23 16:30 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
2015-04-23 16:42 ` Aaron Ecay
2015-04-23 16:13 ` Charles C. Berry
2015-04-23 16:29 ` Rainer M Krug [this message]
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=0A59ABA8-865B-44CE-823A-0CC168983981@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).