emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Hendy <jw.hendy@gmail.com>
To: Jeremie Juste <jeremiejuste@gmail.com>
Cc: Jack Kamm <jackkamm@gmail.com>,
	emacs-orgmode <emacs-orgmode@gnu.org>,
	"Berry, Charles" <ccberry@health.ucsd.edu>,
	Ilja Kocken <i.j.kocken@uu.nl>, Dylan Schwilk <dylan@schwilk.org>
Subject: Re: Help debugging R source code block output problem with :session
Date: Wed, 12 Jan 2022 09:04:48 -0600	[thread overview]
Message-ID: <CA+M2ft_sg=CQd7W_HjLzwEFVuK9pG_NGR15xop3OU0i2G3ccvA@mail.gmail.com> (raw)
In-Reply-To: <87a6g1l7fd.fsf@gmail.com>

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

On Wed, Jan 12, 2022 at 1:50 AM Jeremie Juste <jeremiejuste@gmail.com> wrote:
>
> Hello John,
>
> Many thanks for reporting.  I'm short of time right now, but I'll take a closer look at the problem over
> the weekend and keep you posted. Could you let me know which version of
> org-mode you are currently using?

Sure thing and thanks for the quick note! I use org from git and
*thought* it used to report the most recent release tag, but I see:

$ git log
commit 7fa8173282f85c2ca03cc7f51f28f6adfb250610 (HEAD -> master,
origin/master, origin/HEAD)
Author: Ian Martins <ianxm@jhu.edu>
Date:   Sat Jan 16 15:52:21 2021 -0500

But Mx-version:
Org mode version 9.4.4 (release_9.4.4-186-g7fa817.dirty @
/home/jwhendy/.elisp/org/lisp/)

So perhaps it appends the git commit to the system version?

Btw, it's dirty as I was able to apply Jack's patches (with some mods)
successfully and am a happy camper. In case it's helpful, I attached
the patches as I applied them (first -1, then -2) to this org-version.
Nothing special, they are just Jack's patches with a couple sections
removed (one change was already present, and I removed the adjustments
to the testing file as they were failing).

Thanks so much to all of you who contributed to that, as I'm so happy
that I can at least continue on with my report at this point with good
looking output!

Many thanks,
John

>
> Best regards,
> Jeremie Juste
>
>
> On Tuesday, 11 Jan 2022 at 17:36, John Hendy wrote:
> > Greetings,
> >
> > Apologies for writing off-list, but I don't have the original thread
> > anymore to reply to. I just pulled this group in directly from the
> > email I found... I just got bitten by this as well and burned most of
> > my afternoon trying to figure out what the issue was.
> >
> > Any further thoughts on a patch that could be finalized/applied?
> >
> > Is the one from the thread still the best from your continued experience?
> > https://list.orgmode.org/87zgxc42qg.fsf@gmail.com/
> >
> > This r/orgmode post was what finally got me to the existence of this
> > as a previous issue (I'd just sent my own email to list as my
> > searching did not find the above):
> > https://www.reddit.com/r/orgmode/comments/pt3em4/source_block_modifying_format_of_results_r/
> >
> > And it links to a patch as well:
> > https://gist.github.com/gtuckerkellogg/e356d20497cfdc8e4fc683412e320e3e
> >
> > Many thanks,
> > John

[-- Attachment #2: ob-R-1.patch --]
[-- Type: text/x-patch, Size: 1724 bytes --]

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 5e9d35f58..b37e3965a 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -437,24 +439,23 @@ (defun org-babel-R-evaluate-session
 	  (org-babel-import-elisp-from-file tmp-file '(16)))
 	column-names-p)))
     (output
-     (mapconcat
-      'org-babel-chomp
-      (butlast
-       (delq nil
-	     (mapcar
-	      (lambda (line) (when (> (length line) 0) line))
-	      (mapcar
-	       (lambda (line) ;; cleanup extra prompts left in output
-		 (if (string-match
-		      "^\\([>+.]\\([ ][>.+]\\)*[ ]\\)"
-		      (car (split-string line "\n")))
-		     (substring line (match-end 1))
-		   line))
-	       (org-babel-comint-with-output (session org-babel-R-eoe-output)
-		 (insert (mapconcat 'org-babel-chomp
-				    (list body org-babel-R-eoe-indicator)
-				    "\n"))
-		 (inferior-ess-send-input)))))) "\n"))))
+     (let* ((tmp-file (org-babel-temp-file "R-")))
+       (with-temp-file tmp-file
+	 (insert (concat body "\n" org-babel-R-eoe-indicator)))
+       (with-current-buffer session
+	 (let* ((process (get-buffer-process (current-buffer)))
+		(string-buffer "")
+		(comint-output-filter-functions
+		 (cons (lambda (text) (setq string-buffer
+					    (concat string-buffer text)))
+		       comint-output-filter-functions)))
+	   (ess-send-string
+	    process (format "source('%s', print.eval=TRUE)"
+			    (org-babel-process-file-name tmp-file 'noquote)))
+	   (while (not (string-match (regexp-quote org-babel-R-eoe-output)
+				     string-buffer))
+	     (accept-process-output process))
+	   (substring string-buffer 0 (match-beginning 0))))))))
 
 (defun org-babel-R-process-value-result (result column-names-p)
   "R-specific processing of return value.


[-- Attachment #3: ob-R-2.patch --]
[-- Type: text/x-patch, Size: 1044 bytes --]

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index b37e3965a..5ddf0ebd1 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -441,7 +441,7 @@ (defun org-babel-R-evaluate-session
     (output
      (let* ((tmp-file (org-babel-temp-file "R-")))
        (with-temp-file tmp-file
-	 (insert (concat body "\n" org-babel-R-eoe-indicator)))
+	 (insert body))
        (with-current-buffer session
 	 (let* ((process (get-buffer-process (current-buffer)))
 		(string-buffer "")
@@ -450,8 +450,9 @@ (defun org-babel-R-evaluate-session
 					    (concat string-buffer text)))
 		       comint-output-filter-functions)))
 	   (ess-send-string
-	    process (format "source('%s', print.eval=TRUE)"
-			    (org-babel-process-file-name tmp-file 'noquote)))
+	    process (format "tryCatch(source('%s', print.eval=TRUE), finally=print(%s))"
+			    (org-babel-process-file-name tmp-file 'noquote)
+			    org-babel-R-eoe-indicator))
 	   (while (not (string-match (regexp-quote org-babel-R-eoe-output)
 				     string-buffer))
 	     (accept-process-output process))

  reply	other threads:[~2022-01-12 15:40 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 23:36 Help debugging R source code block output problem with :session John Hendy
2022-01-12  7:49 ` Jeremie Juste
2022-01-12 15:04   ` John Hendy [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-08-28 20:11 Dylan Schwilk
2020-08-29  2:36 ` Jack Kamm
2020-08-29  4:07   ` Dylan Schwilk
2020-08-29  7:24     ` Jack Kamm
2020-08-29 20:35       ` Berry, Charles via General discussions about Org-mode.
2020-08-30  4:37         ` Dylan Schwilk
2020-08-30 15:08         ` Jack Kamm
2020-09-07  8:18         ` Jack Kamm
2020-09-07  8:45           ` Jack Kamm
2020-09-07 17:37             ` Berry, Charles via General discussions about Org-mode.
2020-09-07 20:07               ` Jack Kamm
2020-09-07 22:12                 ` Berry, Charles via General discussions about Org-mode.
2020-09-08  1:06                   ` Jack Kamm
2020-09-08  2:08                     ` Berry, Charles via General discussions about Org-mode.
2020-09-08 14:51                       ` Jack Kamm
2020-09-08 16:45                         ` Berry, Charles via General discussions about Org-mode.
2020-09-08 17:41                           ` Jack Kamm
2020-09-18 16:39                             ` Dylan Schwilk
2020-10-28 13:13                 ` Jack Kamm
2020-10-28 13:46                   ` Jeremie Juste
2020-08-30  4:18       ` Dylan Schwilk
2021-05-03  8:53       ` Jeremie Juste

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='CA+M2ft_sg=CQd7W_HjLzwEFVuK9pG_NGR15xop3OU0i2G3ccvA@mail.gmail.com' \
    --to=jw.hendy@gmail.com \
    --cc=ccberry@health.ucsd.edu \
    --cc=dylan@schwilk.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=i.j.kocken@uu.nl \
    --cc=jackkamm@gmail.com \
    --cc=jeremiejuste@gmail.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).