[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] ob-R, problem with try/catch
From: |
Rainer M Krug |
Subject: |
Re: [O] ob-R, problem with try/catch |
Date: |
Thu, 23 Apr 2015 18:20:10 +0200 |
Envoyé de mon iPhone
> Le 23 avr. 2015 à 17:53, Thomas S. Dye <address@hidden> a écrit :
>
> Aloha Rainer,
>
Hi Thomas,
> Rainer M Krug <address@hidden> 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
- [O] ob-R, problem with try/catch, Thomas S. Dye, 2015/04/22
- Re: [O] ob-R, problem with try/catch, Charles C. Berry, 2015/04/22
- Re: [O] ob-R, problem with try/catch, Charles C. Berry, 2015/04/23
- Re: [O] ob-R, problem with try/catch, Rainer M Krug, 2015/04/23
- Re: [O] ob-R, problem with try/catch, Thomas S. Dye, 2015/04/23
- Re: [O] ob-R, problem with try/catch, Aaron Ecay, 2015/04/23
- Re: [O] ob-R, problem with try/catch, Thomas S. Dye, 2015/04/23
- Re: [O] ob-R, problem with try/catch, Nicolas Goaziou, 2015/04/26
- Re: [O] ob-R, problem with try/catch, Charles C. Berry, 2015/04/26
- Re: [O] ob-R, problem with try/catch, Nicolas Goaziou, 2015/04/26
Re: [O] ob-R, problem with try/catch, Thomas S. Dye, 2015/04/23