From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Berry, Charles" Subject: Re: R source code block :session Date: Sun, 30 Sep 2018 18:03:45 +0000 Message-ID: References: <87wor3ko9i.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6g4c-0005S5-Jn for emacs-orgmode@gnu.org; Sun, 30 Sep 2018 14:04:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g6g4X-0005Ta-Ie for emacs-orgmode@gnu.org; Sun, 30 Sep 2018 14:04:06 -0400 Received: from iport-acv3-out.ucsd.edu ([132.239.0.4]:54357) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1g6g4V-0005Q4-LZ for emacs-orgmode@gnu.org; Sun, 30 Sep 2018 14:04:01 -0400 In-Reply-To: <87wor3ko9i.fsf@gmail.com> Content-Language: en-US Content-ID: <0A6D8DAC2DDACD47886989BF15CBB648@AD.UCSD.EDU> 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" To: Seb Cc: "emacs-orgmode@gnu.org" > On Sep 30, 2018, at 8:18 AM, Seb wrote: >=20 > Hello, >=20 > I'm running into a couple of issues with R source code blocks using > :session : >=20 > ---<--------------------cut here---------------start------------------->-= -- > #+NAME: test01 > #+BEGIN_SRC R :session :results output > library(ascii) > numstbl <- table(1:4, 1:4) > summary(numstbl) > #+END_SRC >=20 > #+RESULTS: test01 > : R> Number of cases in table: 4 > : Number of factors: 2 > : Test for independence of all factors: > : Chisq =3D 12, df =3D 9, p-value =3D 0.2 > : Chi-squared approximation may be incorrect > ---<--------------------cut here---------------end--------------------->-= -- >=20 > Notice the "R> " prompt that prefixes the actual output. =20 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 t= hat 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=09 "^\\([>+.]\\([ ][>.+]\\)*[ ]\\)" and propose a fix that handles your case. =20 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=3D"R> ")` in my > ~/.Rprofile. >=20 > The other problem: >=20 > ---<--------------------cut here---------------start------------------->-= -- > #+NAME: test02 > #+BEGIN_SRC R :results output org > library(ascii) > options(asciiType=3D"org") > ascii(summary(table(1:4, 1:4))) > #+END_SRC >=20 > #+RESULTS: test02 > #+BEGIN_SRC org > - Number of cases in table: 4 > - Number of factors: 2 > - Test for independence of all factors: > - Chisq =3D 12, df =3D 9, p-value =3D 0.2 > - Chi-squared approximation may be incorrect > #+END_SRC > ---<--------------------cut here---------------end--------------------->-= -- >=20 > 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. >=20 The manual says it is wrapped as you saw above. See=20 (info "(org) Results of Evaluation") Unfortunately, the worg pages are not as well curated as the manual. So ad= vice that is out of date persists. You might want to use `:wrap' to get the behavior you seek, but be aware th= ere is no `org' special block in the current releases. So even if you get t= o wrap the results in begin/end-org, it will probably not behave as you wan= t or expect. Perhaps `drawer' will satisfy your needs. Chuck ps. Org mode version 9.1.14