Re: Help debugging R source code block output problem with :session
Thanks. This patch works for my org files. On Tue 08 Sep 2020 at 12:41, Jack Kamm wrote: Hi Chuck, this is already present in `org-babel-R-evaluate-session' in the call to `org-babel-comint-eval-invisibly-and-wait-for-file'' just a couple of lines further down in the `(cl-case result-type (value ...))' branch. The other use of `tmp-file' in that block is the one that requires the prefix, right? So nothing more to fix. ?? You're right, I didn't notice that it's already present -- nothing more to fix. Jack --
Re: Help debugging R source code block output problem with :session
Thanks for the workaround idea of grabbing the results as a string. I'm not sure why this issue cropped up for me right now when I did not run into it in previous years. But I have run into other :results output issues in the past when ess changed. Thanks, Dylan On Sat 29 Aug 2020 at 15:35, Berry, Charles wrote: This problem has been bugging people for years and previous attempts to solve it have always run up against creating more problems in the process of solving this one. This workaround gives the same results with or without `:session "NEW"' and same as OPs first src block: #+header: :prologue "capture.output({" :epilogue "})" #+begin_src R :results value verbatim :session "NEW" print(" ") print("one three") print("end") #+end_src If you do decide to dig into solving this, please be sure that remote sessions and graphical outputs are not broken. test-ob-R.el does not cover those cases. In fact, it is pretty short, so there are probably other things that could break without `make test' complaining. HTH, Chuck On Aug 29, 2020, at 12:24 AM, Jack Kamm wrote: Hi Dylan, The patch does fix that issue -- but it introduces a different bug for code blocks with ~:session~: the R block now only produces output from the last statement evaluated. Of course, you're right. Good catch. Here's another attempt. It fixes the issue by modifying the R comint regular expression, requiring it to match at the beginning of the line. --
Re: Help debugging R source code block output problem with :session
Yes, the modified comint-prompt-regexp works for my use cases and I'm back to expected output and what I had last time I taught the course. This was my instinct for a simple solution as well, but I've not tested against remote sessions and graphical outputs as Charles Berry warns. I'll take a look at your ob-session-async, thanks! -Dylan On Sat 29 Aug 2020 at 02:24, Jack Kamm wrote: Hi Dylan, The patch does fix that issue -- but it introduces a different bug for code blocks with ~:session~: the R block now only produces output from the last statement evaluated. Of course, you're right. Good catch. Here's another attempt. It fixes the issue by modifying the R comint regular expression, requiring it to match at the beginning of the line. I think this should fix most cases, including the examples you sent. Still, it's not totally robust -- for example, it will still mangle multiline strings, if one of the lines starts with a substring that looks like a prompt. I'd be interested to hear if the attached patch works for the common cases you encounter, such as with tibbles. As an aside, I personally use an alternative implementation of ob-R sessions that doesn't suffer from this issue, and also provides some other benefits like async evaluation [1]. I'm planning to submit these changes to org-mode someday, but am not ready yet. But you may want to check it out, it was able to solve the issue in the other thread I linked as well. [1] https://github.com/jackkamm/ob-session-async From 9eaf81d708f88d06f14f9b6b9cf4182dd0fbb997 Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Sat, 29 Aug 2020 00:07:58 -0700 Subject: [PATCH] ob-R: Fix prompt mangling in session output * lisp/ob-R.el (org-babel-R-evaluate-session): Force comint prompt regexp to start at beginning of line, to prevent org-babel-comint-with-output from splitting mid-line. Fixes https://orgmode.org/list/875zgjh8wn@gmail.com/ and https://orgmode.org/list/87r1rqled0.fsf@havana/ --- lisp/ob-R.el | 12 +++- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 5e9d35f58..10b3b6fe3 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -450,11 +450,13 @@ (defun org-babel-R-evaluate-session (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" + (with-current-buffer session + (let ((comint-prompt-regexp (concat "^" comint-prompt-regexp))) + (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" (defun org-babel-R-process-value-result (result column-names-p) "R-specific processing of return value. --
Re: Help debugging R source code block output problem with :session
Hi Jack, The patch does fix that issue -- but it introduces a different bug for code blocks with ~:session~: the R block now only produces output from the last statement evaluated. #+begin_src R :results output :exports both :session 4.0 * 3.5 log(10) # natural log log10(10) (3 + 1) * 5 3^-1 1/0 #+end_src #+results: : [1] Inf Without the ~:session header~ the output is as it was before the patch: #+results: : [1] 14 : [1] 2.302585 : [1] 1 : [1] 20 : [1] 0.333 : [1] Inf -Dylan
Help debugging R source code block output problem with :session
I returned to an org file this week and found that I am getting some strange source code block output for R code when I use the :session header. I have been able to duplicate this with a minimal init file. I strongly suspect it is some problem at my end but perhaps folks here can help me know here to look? It occurs with a minimal emacs initialization. First, here is a small org file example of the problem. In the second results block the ">" appears to be treated as a prompt line to strip from output but only when a session is started. This happens with any ">" in output when the :session header occurs. the problem is dramatic when printing tibbles where the column modes are enclosed in angle brackets. test.org ** Test org babel R output prompt problem #+begin_src R :results output print(" ") print("one three") print("end") #+end_src #+RESULTS: : [1] " " : [1] "one three" : [1] "end" #+begin_src R :results output :session "NEW" print(" ") print("one three") print("end") #+end_src #+RESULTS: : [1] "< : < : " : [1] "one < : three" : [1] "end" <<< The second block produces the bad output. This occurs with a minimal setup. I start emacs with emacs -Q -l "~/debugorg.el" where debugorg.el is: require 'package) add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/;) t) add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/;) t) package-initialize) require 'ess-site) (org-babel-do-load-languages 'org-babel-load-languages '((R . t))) << emacs version 26.3 org-mode version 9.3.7 ess version 18.10.3snapshot --
Re: [O] org babel R source blocks :results output with :session includes extra blank lines
Thank you and my apologies. Seeing the session output you posted convinced me the problem was with my ess settings. Of course I should have known that because I could find no-one else with the same problem and I could see no change to ob-R.el in the git repo in the past months that could have affected this. The problem turned out to be the ess variable ess-eval-visibly. The default, nil works fine with ob-R (doc: "If nil, ESS doesn’t print input commands and doesn’t wait for the process."). I had accidentally set to 'nowait (doc: If ’nowait, ESS still shows the input commands, but don’t wait for the process.). My apologies for the spurious post. I had not realized that I was setting that ess variable. Sincerely, Dylan On 08/28/2018 11:57 AM, Berry, Charles wrote: > Cannot confirm. See inline. > >> On Aug 28, 2018, at 7:48 AM, Dylan Schwilk wrote: >> >> Hello, >> >> I recently have run into a change in output from my R language source code >> blocks. >> >> I have found that when I include :session to the source block header, I now >> get >> extra blank lines in the #+results. This has broken my lecture slides for my >> courses with too much extra blank space. >> >> for example: >> >> #+begin_src R :results output :exports both :session >> 1 + 2 >> 3 + 4 >> print("the end") >> #+end_src >> >> #+results: >> : [1] 3 >> : >> : [1] 7 >> : >> : [1] "the end" >> > > With the :session arg I get the output as you show it below. > > This was with master on commit f79545 from last month and on today's master > (commit 38a8901). > >> >> I do not have this issue when I omit the :session header argument, eg: >> >> #+begin_src R :results output :exports both >> 1 + 2 >> 3 + 4 >> print("the end") >> #+end_src >> >> #+results: >> : [1] 3 >> : [1] 7 >> : [1] "the end" >> >> > > > FWIW, my R session looks like this > > > --8<---cut here---start->8--- > [...] > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for an HTML browser interface to help. > Type 'q()' to quit R. > >> setwd('/Users/cberry/') >> 1 + 2 > 3 + 4 > print("the end") > 'org_babel_R_eoe' > [1] 3 >> [1] 7 >> > [1] "the end" >> [1] "org_babel_R_eoe" > --8<---cut here---end--->8--- > > If this is what your session looks like, then we need to dig deeper into ob-R. > > HTH, > > Chuck > > > >
[O] org babel R source blocks :results output with :session includes extra blank lines
Hello, I recently have run into a change in output from my R language source code blocks. I have found that when I include :session to the source block header, I now get extra blank lines in the #+results. This has broken my lecture slides for my courses with too much extra blank space. for example: #+begin_src R :results output :exports both :session 1 + 2 3 + 4 print("the end") #+end_src #+results: : [1] 3 : : [1] 7 : : [1] "the end" I do not have this issue when I omit the :session header argument, eg: #+begin_src R :results output :exports both 1 + 2 3 + 4 print("the end") #+end_src #+results: : [1] 3 : [1] 7 : [1] "the end" I am using org-mode version 9.1.13, emacs 25.2.2 and R version 3.4.4 (2018-03-15) with no .Rprofile. This does not happen with python source blocks, only with R Sincerely, Dylan
Re: [O] Archive subtrees hierarchical (keep the parent structure)
Dear Florian, I just found this code you wrote and it is exactly what I wanted for my archiving. But I found one little issue. I discovered that this interacts with the setting org-yank-adjusted-subtrees because it calls org-yank. With (setq org-yank-justed-subtrees t), the archived subtree is not pasted in as a child of the created hierarchy, but ends up as a sibling because org-yank calls org-paste-subtree. My current workaround is to set org-yank-adjusted-subtrees nil, but perhaps there is a clean way to turn off this setting in org-yank so that org-paste-subtree is not called in this particular case regardless of the value of org-yank-adjusted-subtrees? - Dylan Schwilk On Tue, Aug 5, 2014 at 1:00 PM, Ken Mankoff mank...@gmail.com wrote: Yes that works perfectly. Not sure why I had memorized a different keystroke. Thank you! On Tue, Aug 5, 2014 at 1:46 PM, Florian Adamsky fa-orgm...@haktar.org wrote: Dear Ken, On Tuesday, Aug 05 2014, Ken Mankoff mank...@gmail.com wrote: You are correct that M-x org-archive-subtree-hierarchical works just fine. But I can't get it to work with the default keybinding as you show above. C-c C-x C-s is my (the?) default keybinding for archiving trees/subtrees. Is this the correct keybinding? according to the documentation the default keybinding to archive the current entry is C-c C-x C-a. Could you try that instead? [...] Best -- Florian Adamsky http://florian.adamsky.it/