emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* ob-R, problem with try/catch
@ 2015-04-22 22:03 Thomas S. Dye
  2015-04-23  2:23 ` Charles C. Berry
  0 siblings, 1 reply; 17+ messages in thread
From: Thomas S. Dye @ 2015-04-22 22:03 UTC (permalink / raw)
  To: Org-mode

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..))
|   rm(g)                                 
| #+end_src                               
`-----------------------------------------

After eaa3a761dae, I get an error and an empty output file.

I can work around this error by removing the line "rm(g)", however, I'd
like to keep the session "clean" and not have a bunch of variables
hanging around.

Is there a way to do this with ob-R.el in its current state?  Or, should
I adopt a different set of habits?

All the best,
Tom

-- 
T.S. Dye & Colleagues, Archaeologists
735 Bishop St, Suite 315, Honolulu, HI 96813
Tel: 808-529-0866, Fax: 808-529-0884
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  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  6:35   ` Thomas S. Dye
  0 siblings, 2 replies; 17+ messages in thread
From: Charles C. Berry @ 2015-04-23  2:23 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Org-mode

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 can work around this error by removing the line "rm(g)",

Right. Then, the expression returned by tryCatch is

 	g + geom_histogram(aes(y=..density..))

which is autoprinted giving the graph.

When in doubt, there is no harm in explicitly print()ing objects that 
would have been autoprinted otherwise.

For reference, here is what org-babel-execute:R produces for your src 
block (lightly formatted for readability):

#+BEGIN_SRC R
   pdf(file=\"r/adze_wt_log.pdf\",width=4,height=3)
   tryCatch({
                g <- ggplot(x, aes(x = weight))
                g + geom_histogram(aes(y=..density..))
                rm(g)
            },
            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()
#+END_SRC

HTH,

Chuck

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  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:13     ` Charles C. Berry
  2015-04-23  6:35   ` Thomas S. Dye
  1 sibling, 2 replies; 17+ messages in thread
From: Rainer M Krug @ 2015-04-23  5:40 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: Org-mode, Thomas S. Dye



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. 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. 

Thanks,

Rainer

> 
>> I can work around this error by removing the line "rm(g)",
> 
> Right. Then, the expression returned by tryCatch is
> 
>    g + geom_histogram(aes(y=..density..))
> 
> which is autoprinted giving the graph.
> 
> When in doubt, there is no harm in explicitly print()ing objects that would have been autoprinted otherwise.
> 
> For reference, here is what org-babel-execute:R produces for your src block (lightly formatted for readability):
> 
> #+BEGIN_SRC R
>  pdf(file=\"r/adze_wt_log.pdf\",width=4,height=3)
>  tryCatch({
>               g <- ggplot(x, aes(x = weight))
>               g + geom_histogram(aes(y=..density..))
>               rm(g)
>           },
>           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()
> #+END_SRC
> 
> HTH,
> 
> Chuck
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-04-23  2:23 ` Charles C. Berry
  2015-04-23  5:40   ` Rainer M Krug
@ 2015-04-23  6:35   ` Thomas S. Dye
  1 sibling, 0 replies; 17+ messages in thread
From: Thomas S. Dye @ 2015-04-23  6:35 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: Org-mode

Aloha Chuck,

"Charles C. Berry" <ccberry@ucsd.edu> writes:

> 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).

Perfect--a graph in the file and a clean session.  Thanks!

All the best,
Tom

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  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:13     ` Charles C. Berry
  1 sibling, 1 reply; 17+ messages in thread
From: Thomas S. Dye @ 2015-04-23 15:53 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Org-mode, Charles C. Berry

Aloha Rainer,

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.  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.

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 

hth,
Tom

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-04-23  5:40   ` Rainer M Krug
  2015-04-23 15:53     ` Thomas S. Dye
@ 2015-04-23 16:13     ` Charles C. Berry
  2015-04-23 16:29       ` Rainer M Krug
  1 sibling, 1 reply; 17+ messages in thread
From: Charles C. Berry @ 2015-04-23 16:13 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Org-mode, Thomas S. Dye

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2470 bytes --]

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



HTH,

Chuck

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-04-23 15:53     ` Thomas S. Dye
@ 2015-04-23 16:20       ` Rainer M Krug
  2015-04-23 16:42         ` Aaron Ecay
  0 siblings, 1 reply; 17+ messages in thread
From: Rainer M Krug @ 2015-04-23 16:20 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Org-mode, Charles C. Berry



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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  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-26 12:49         ` Nicolas Goaziou
  0 siblings, 2 replies; 17+ messages in thread
From: Rainer M Krug @ 2015-04-23 16:29 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: Org-mode, Thomas S. Dye



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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-04-23 16:20       ` Rainer M Krug
@ 2015-04-23 16:42         ` Aaron Ecay
  0 siblings, 0 replies; 17+ messages in thread
From: Aaron Ecay @ 2015-04-23 16:42 UTC (permalink / raw)
  To: Rainer M Krug, Thomas S. Dye; +Cc: Org-mode, Charles C. Berry

Hello all,

2015ko apirilak 23an, Rainer M Krug-ek idatzi zuen:
>> 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.

Before this change, the code was fed line-by-line to the R interpreter,
and thus each line was auto printed.  (Technically, the result of each
expresion, whcih could span multiple lines.)  After this change, the
code is one expression, and only the result of the whole block is
printed.  Thus the different behavior.

The previous behavior was not unproblematic.  If a code block contained
more than one plot, the results would have been odd: for a pdf device a
multi-page pdf is generated.  For jpg/png, several files are generated
with a sequence number appended to each.

The principled approach is to use the evaluate package for this.  I had
worked on a patch to move towards this approach, but the effort stalled
when Charles Berry reported some regressions with remote sessions, which
I was never able to reproduce (and thus fix) satisfactorily.  The patch
is here: <http://mid.gmane.org/87k35orl2w.fsf@gmail.com>.

In any case, it is clear that one of the workarounds discussed in
this thread should be used.  Perhaps we should generate a warning for
“:results output graphics” R code blocks, since they could produce
this strange situation.  A priori, I expect that “:results value
graphics” should be free from this problem.

-- 
Aaron Ecay

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  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-26 12:49         ` Nicolas Goaziou
  1 sibling, 1 reply; 17+ messages in thread
From: Thomas S. Dye @ 2015-04-23 17:11 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Org-mode, Charles C. Berry

Aloha Rainer,

Rainer M Krug <r.m.krug@gmail.com> writes:

> 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

IIRC :results output graphics is needed for the ggplot package.

All the best,
Tom

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-04-23 17:11         ` Thomas S. Dye
@ 2015-04-23 22:39           ` Aaron Ecay
  2015-04-23 23:36             ` Thomas S. Dye
  0 siblings, 1 reply; 17+ messages in thread
From: Aaron Ecay @ 2015-04-23 22:39 UTC (permalink / raw)
  To: Thomas S. Dye, Rainer M Krug; +Cc: Org-mode, Charles C. Berry

Hi Tom,

2015ko apirilak 23an, "Thomas S. Dye"-ek idatzi zuen:
> 
> IIRC :results output graphics is needed for the ggplot package.

Hmm.  This is the case if the code is *not* evaluated in a session.  In
a session, either value or output result types work.  (All this has been
tested with a recent master version.)  An unfortunate situation – IMO
the value type ought to work outside of a session, provided that the
value of the last expression in the block is a ggplot object.

Here’s a code block that can be adapted to test various combinations:

#+begin_src R :results output graphics :file foo.png :session *foo*
  library(ggplot2)
  ggplot(data.frame(x = rnorm(10), y = rnorm(10)),
         aes(x = x, y = y)) +
    geom_point()
#+end_src

-- 
Aaron Ecay

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-04-23 22:39           ` Aaron Ecay
@ 2015-04-23 23:36             ` Thomas S. Dye
  0 siblings, 0 replies; 17+ messages in thread
From: Thomas S. Dye @ 2015-04-23 23:36 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Org-mode, Charles C. Berry

Hi Aaron,

Aaron Ecay <aaronecay@gmail.com> writes:

> Hi Tom,
>
> 2015ko apirilak 23an, "Thomas S. Dye"-ek idatzi zuen:
>> 
>> IIRC :results output graphics is needed for the ggplot package.
>
> Hmm.  This is the case if the code is *not* evaluated in a session.  In
> a session, either value or output result types work.  (All this has been
> tested with a recent master version.)

Yes, indeed.  I'd forgotten this distinction, which Erik Iverson spelled
out clearly several years ago:
http://article.gmane.org/gmane.emacs.orgmode/26082

Unless Erik minds, I'll work his post into ob-doc-R when I find some
time.  IMO, it would be nice to have this kind of systematic description
in the first place one goes for help.

> An unfortunate situation – IMO
> the value type ought to work outside of a session, provided that the
> value of the last expression in the block is a ggplot object.
>
> Here’s a code block that can be adapted to test various combinations:
>
> #+begin_src R :results output graphics :file foo.png :session *foo*
>   library(ggplot2)
>   ggplot(data.frame(x = rnorm(10), y = rnorm(10)),
>          aes(x = x, y = y)) +
>     geom_point()
> #+end_src

Thanks, this code will be useful as I pick up this project, which was
the first time I tried to do something substantial with Org mode.  I'm
going to find a ton of cruft ...

All the best,
Tom

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-04-23 16:29       ` Rainer M Krug
  2015-04-23 17:11         ` Thomas S. Dye
@ 2015-04-26 12:49         ` Nicolas Goaziou
  2015-04-26 17:11           ` Charles C. Berry
  1 sibling, 1 reply; 17+ messages in thread
From: Nicolas Goaziou @ 2015-04-26 12:49 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Org-mode, Charles C. Berry, Thomas S. Dye

Hello,

Rainer M Krug <r.m.krug@gmail.com> writes:

> Possible a candidate for the new linting library for org, to mark it
> as an invalid argument combination

Done. Do you know any other such combinations?


Regards,

--
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  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
  0 siblings, 2 replies; 17+ messages in thread
From: Charles C. Berry @ 2015-04-26 17:11 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode, Thomas S. Dye, Rainer M Krug

On Sun, 26 Apr 2015, Nicolas Goaziou wrote:

> Hello,
>
> Rainer M Krug <r.m.krug@gmail.com> writes:
>
>> Possible a candidate for the new linting library for org, to mark it
>> as an invalid argument combination
>
> Done. Do you know any other such combinations?

Except for langs emacs-lisp, clojure, ruby, picolisp, and 
python `:results pp' does nothing.

mathematica refers to "pp" but I don't get what it does - it looks like 
"raw" would be a more suitable :results format.

Of course, somebody could add a pretty print routine for another language, 
so maybe avoid hard coding the langs.

I guess this would be 'low' trust?


==


For inline src block and inline babel call, `:results list' and `:results 
table' are invalid and throw an error in `org-babel-insert-result'.

HTH,

Chuck

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-04-26 17:11           ` Charles C. Berry
@ 2015-04-26 17:28             ` Nicolas Goaziou
  2015-05-04  8:35             ` Rainer M Krug
  1 sibling, 0 replies; 17+ messages in thread
From: Nicolas Goaziou @ 2015-04-26 17:28 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: Org-mode, Thomas S. Dye, Rainer M Krug

"Charles C. Berry" <ccberry@ucsd.edu> writes:

> Except for langs emacs-lisp, clojure, ruby, picolisp, and python
> `:results pp' does nothing.
>
> mathematica refers to "pp" but I don't get what it does - it looks
> like "raw" would be a more suitable :results format.
>
> Of course, somebody could add a pretty print routine for another
> language, so maybe avoid hard coding the langs.

Done.

> I guess this would be 'low' trust?

The whole check already has `low' trust anyway.

> For inline src block and inline babel call, `:results list' and
> `:results table' are invalid and throw an error in
> `org-babel-insert-result'.

Done.


Regards,

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  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
  1 sibling, 1 reply; 17+ messages in thread
From: Rainer M Krug @ 2015-05-04  8:35 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: Org-mode, Thomas S. Dye, Nicolas Goaziou, Rainer M Krug

[-- Attachment #1: Type: text/plain, Size: 1792 bytes --]

"Charles C. Berry" <ccberry@ucsd.edu> writes:

> On Sun, 26 Apr 2015, Nicolas Goaziou wrote:
>
>> Hello,
>>
>> Rainer M Krug <r.m.krug@gmail.com> writes:
>>
>>> Possible a candidate for the new linting library for org, to mark it
>>> as an invalid argument combination
>>
>> Done. Do you know any other such combinations?
>
> Except for langs emacs-lisp, clojure, ruby, picolisp, and python
> `:results pp' does nothing.
>
> mathematica refers to "pp" but I don't get what it does - it looks
> like "raw" would be a more suitable :results format.
>
> Of course, somebody could add a pretty print routine for another
> language, so maybe avoid hard coding the langs.

Thinking about it, I don't think that the combinations should be defined
in the linting library, but in the language definition (ob-XXX.el), by a
function which returns all tested combinations, i.e. all combinations
which have been tested, including if they work or not. The linting
library could then query these lists and use them.

This would keep the language definition in the ob-XXX.el file and make
it easier to maintain.

Rainer


>
> I guess this would be 'low' trust?
>
>
> ==
>
>
> For inline src block and inline babel call, `:results list' and
> `:results table' are invalid and throw an error in
> `org-babel-insert-result'.
>
> HTH,
>
> Chuck

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug

PGP: 0x0F52F982

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: ob-R, problem with try/catch
  2015-05-04  8:35             ` Rainer M Krug
@ 2015-05-04 19:03               ` Nicolas Goaziou
  0 siblings, 0 replies; 17+ messages in thread
From: Nicolas Goaziou @ 2015-05-04 19:03 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: Org-mode, Charles C. Berry, Thomas S. Dye, Rainer M Krug

Hello,

Rainer M Krug <Rainer@krugs.de> writes:

> Thinking about it, I don't think that the combinations should be defined
> in the linting library, but in the language definition (ob-XXX.el), by a
> function which returns all tested combinations, i.e. all combinations
> which have been tested, including if they work or not. The linting
> library could then query these lists and use them.
>
> This would keep the language definition in the ob-XXX.el file and make
> it easier to maintain.

This is already the case. See, e.g., `org-babel-header-args:R' and
`org-babel-common-header-args-w-values'.

The linting library doesn't hard-code any combination anymore.


Regards,

-- 
Nicolas Goaziou                                                0x80A93738

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2015-05-04 19:02 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).