* R source code block :session
@ 2018-09-30 15:18 Seb
2018-09-30 18:03 ` Berry, Charles
0 siblings, 1 reply; 3+ messages in thread
From: Seb @ 2018-09-30 15:18 UTC (permalink / raw)
To: emacs-orgmode
Hello,
I'm running into a couple of issues with R source code blocks using
:session :
---<--------------------cut here---------------start------------------->---
#+NAME: test01
#+BEGIN_SRC R :session :results output
library(ascii)
numstbl <- table(1:4, 1:4)
summary(numstbl)
#+END_SRC
#+RESULTS: test01
: R> Number of cases in table: 4
: Number of factors: 2
: Test for independence of all factors:
: Chisq = 12, df = 9, p-value = 0.2
: Chi-squared approximation may be incorrect
---<--------------------cut here---------------end--------------------->---
Notice the "R> " prompt that prefixes the actual output. If the first
line (`library` call) is removed, then the prompt is correctly excluded
from the results output. I do have `options(prompt="R> ")` in my
~/.Rprofile.
The other problem:
---<--------------------cut here---------------start------------------->---
#+NAME: test02
#+BEGIN_SRC R :results output org
library(ascii)
options(asciiType="org")
ascii(summary(table(1:4, 1:4)))
#+END_SRC
#+RESULTS: test02
#+BEGIN_SRC org
- Number of cases in table: 4
- Number of factors: 2
- Test for independence of all factors:
- Chisq = 12, df = 9, p-value = 0.2
- Chi-squared approximation may be incorrect
#+END_SRC
---<--------------------cut here---------------end--------------------->---
According to the documentation
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-R.html, the
results output should be wrapped in #+BEGIN_ORG #+END_ORG, not in
another source code block.
Any tips much appreciated.
Cheers,
--
Seb
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: R source code block :session
2018-09-30 15:18 R source code block :session Seb
@ 2018-09-30 18:03 ` Berry, Charles
2018-09-30 18:10 ` William Denton
0 siblings, 1 reply; 3+ messages in thread
From: Berry, Charles @ 2018-09-30 18:03 UTC (permalink / raw)
To: Seb; +Cc: emacs-orgmode@gnu.org
> On Sep 30, 2018, at 8:18 AM, Seb <spluque@gmail.com> wrote:
>
> Hello,
>
> I'm running into a couple of issues with R source code blocks using
> :session :
>
> ---<--------------------cut here---------------start------------------->---
> #+NAME: test01
> #+BEGIN_SRC R :session :results output
> library(ascii)
> numstbl <- table(1:4, 1:4)
> summary(numstbl)
> #+END_SRC
>
> #+RESULTS: test01
> : R> Number of cases in table: 4
> : Number of factors: 2
> : Test for independence of all factors:
> : Chisq = 12, df = 9, p-value = 0.2
> : Chi-squared approximation may be incorrect
> ---<--------------------cut here---------------end--------------------->---
>
> Notice the "R> " prompt that prefixes the actual output.
The issue is that babel has to clean up dangling prompts from the R session buffer and is currently not smart enough to do this in your case.
Somebody who is well versed in regex's might be able to compare the regex that ess sets in the session buffer
"^[]a-zA-Z0-9.[]*\\(?:[>+.] \\)*> "
and compare that to the current regex just after `;; cleanup extra prompts left in output' in org-babel-R-evaluate-session
"^\\([>+.]\\([ ][>.+]\\)*[ ]\\)"
and propose a fix that handles your case.
However, this is bound to be a bit *fragile* as arbitrary prompts might end up looking like bona fide output and vice versa.
I think your easiest path forward is to use the default R prompt. Or maybe use these header args:
:session :results value drawer :prologue "capture.output({" :epilogue "})"
> If the first
> line (`library` call) is removed, then the prompt is correctly excluded
> from the results output. I do have `options(prompt="R> ")` in my
> ~/.Rprofile.
>
> The other problem:
>
> ---<--------------------cut here---------------start------------------->---
> #+NAME: test02
> #+BEGIN_SRC R :results output org
> library(ascii)
> options(asciiType="org")
> ascii(summary(table(1:4, 1:4)))
> #+END_SRC
>
> #+RESULTS: test02
> #+BEGIN_SRC org
> - Number of cases in table: 4
> - Number of factors: 2
> - Test for independence of all factors:
> - Chisq = 12, df = 9, p-value = 0.2
> - Chi-squared approximation may be incorrect
> #+END_SRC
> ---<--------------------cut here---------------end--------------------->---
>
> According to the documentation
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-R.html, the
> results output should be wrapped in #+BEGIN_ORG #+END_ORG, not in
> another source code block.
>
The manual says it is wrapped as you saw above. See
(info "(org) Results of Evaluation")
Unfortunately, the worg pages are not as well curated as the manual. So advice that is out of date persists.
You might want to use `:wrap' to get the behavior you seek, but be aware there is no `org' special block in the current releases. So even if you get to wrap the results in begin/end-org, it will probably not behave as you want or expect.
Perhaps `drawer' will satisfy your needs.
Chuck
ps. Org mode version 9.1.14
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: R source code block :session
2018-09-30 18:03 ` Berry, Charles
@ 2018-09-30 18:10 ` William Denton
0 siblings, 0 replies; 3+ messages in thread
From: William Denton @ 2018-09-30 18:10 UTC (permalink / raw)
To: Seb; +Cc: emacs-orgmode@gnu.org
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1251 bytes --]
On 30 September 2018, Berry, Charles wrote:
>> Notice the "R> " prompt that prefixes the actual output.
>
> The issue is that babel has to clean up dangling prompts from the R session buffer and is currently not smart enough to do this in your case.
> ...
> I think your easiest path forward is to use the default R prompt. Or maybe use these header args:
>
> :session :results value drawer :prologue "capture.output({" :epilogue "})"
Having the "library" call in its own block, with results silent, also works.
#+NAME: setup
#+BEGIN_SRC R :session :results silent
library(ascii)
#+END_SRC
#+NAME: test01
#+BEGIN_SRC R :session :results output
numstbl <- table(1:4, 1:4)
summary(numstbl)
#+END_SRC
That's how I usually do things, perhaps because I use "ℝ>" as m prompt and I
ran into the same problem but found this got around it (though it's been a while
and I can't remember for sure). It also saves time when rerunning code because
I don't reload stuff over and over.
Bill
--
William Denton :: Toronto, Canada --- Listening to Art: https://listeningtoart.org/
https://www.miskatonic.org/ --- GHG.EARTH: http://ghg.earth/
Caveat lector. --- STAPLR: http://staplr.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-09-30 18:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-30 15:18 R source code block :session Seb
2018-09-30 18:03 ` Berry, Charles
2018-09-30 18:10 ` William Denton
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).