emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: Code block returned no value [9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/26.3/lisp/org/)]
@ 2020-05-03 14:27 Greg Minshall
  2020-05-21  4:16 ` [PATCH] ob-core: Display warning on failure to read results Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Minshall @ 2020-05-03 14:27 UTC (permalink / raw)
  To: emacs-orgmode

hi.  i'm running R code from an org mode file.  i was having a problem
where a code block that *was* returning a value result was not returning
the results into the buffer.

(after long head-scratching) this appears to be because my code was
returning more lines of results than org-table-convert-region-max-lines.

but, i was *not* seeing any error message, nothing to indicate to me why
i was getting no results.  in the test program below, when trying to
return more than 1000 lines, one sees, in the echo area, "Code block
returned no value".  if you go to *Messages*, there you can see an error
message.

i think somehow org/babel should make sure the user sees what limitation
s/he is running into.

the test block below, 'FailsIfnGT999', if run with n <= 999, will return
a table of that many lines.  if run with n > 999, (for me, invoking
"emacs -Q"), you will get empty results, with the message "Code block
returned no value" (which is false, but the interactions between R code,
R, ess, babel, org, etc., are a bit mysterious to the semi-initiated) in
the echo area.

(not invoking via 'emacs -Q', i am running
----
Package: Org mode version 9.3.6 (9.3.6-43-gc77edd-elpa @
/home/minshall/.emacs.d/elpa/org-20200413/)
----
but the results are the same; i'm submitting the bug report from 9.3.6,
but edited the Subject line with the header from an attempt to submit
from 9.1.9.)

cheers, Greg

>>>>
run this first to get R enabled
#+BEGIN_SRC emacs-lisp :results none
  (org-babel-do-load-languages
   'org-babel-load-languages
      '((R . t)))
#+END_SRC

then, run =FailsIfnGT999= first with =n= set to =100=.  notice there
are results.  then, run =FailsIfnGT999= with =n= set to, e.g., 1100.
notice there are *no* results, and the message area at the bottom of
the screen says
: Code block returned no value

now, if you go to the *Messages* buffer, you *will* see the error message, i.e.,
: Error reading results: (user-error Region is longer than ‘org-table-convert-region-max-lines’ (999) lines; not converting)

#+name: FailsIfnGT999
#+begin_src R :results value table :var n=100
result <- data.frame()
for (i in 1:n) {
  result <- rbind(result, data.frame(a=i,b=i+1))
}
result
#+end_src
>>>>

Emacs  : GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.10)
 of 2019-08-29
Package: Org mode version 9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/26.3/lisp/org/)


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

* [PATCH] ob-core: Display warning on failure to read results
  2020-05-03 14:27 Bug: Code block returned no value [9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/26.3/lisp/org/)] Greg Minshall
@ 2020-05-21  4:16 ` Kyle Meyer
  2020-05-21 21:55   ` Greg Minshall
  2020-05-24 16:04   ` Kyle Meyer
  0 siblings, 2 replies; 4+ messages in thread
From: Kyle Meyer @ 2020-05-21  4:16 UTC (permalink / raw)
  To: Greg Minshall, emacs-orgmode

Greg Minshall writes:

> hi.  i'm running R code from an org mode file.  i was having a problem
> where a code block that *was* returning a value result was not returning
> the results into the buffer.
>
> (after long head-scratching) this appears to be because my code was
> returning more lines of results than org-table-convert-region-max-lines.
>
> but, i was *not* seeing any error message, nothing to indicate to me why
> i was getting no results.  in the test program below, when trying to
> return more than 1000 lines, one sees, in the echo area, "Code block
> returned no value".  if you go to *Messages*, there you can see an error
> message.

Thanks for the report and for providing a minimal example.

> i think somehow org/babel should make sure the user sees what limitation
> s/he is running into.

I agree.  Here's my suggestion.

-- >8 --
Subject: [PATCH] ob-core: Display warning on failure to read results

* lisp/ob-core.el (org-babel-import-elisp-from-file): Show handled
errors with display-warning rather than a message because the latter
is quickly overridden by subsequent messages, making it difficult if
not impossible for the user to spot.

The scope of the save-window-excursion call would need to be reduced
for the display-warning buffer to be shown, but nothing appears to
change the window configuration, so just drop the
save-window-excursion call.

Reported-by: Greg Minshall <minshall@umich.edu>
<2449663.1588516024@apollo2.minshall.org>
---
 lisp/ob-core.el | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index ee0dc3d72..2a75ae734 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2941,24 +2941,27 @@ (defun org-babel--string-to-number (string)
 (defun org-babel-import-elisp-from-file (file-name &optional separator)
   "Read the results located at FILE-NAME into an elisp table.
 If the table is trivial, then return it as a scalar."
-  (save-window-excursion
-    (let ((result
-	   (with-temp-buffer
-	     (condition-case err
-		 (progn
-		   (org-table-import file-name separator)
-		   (delete-file file-name)
-		   (delq nil
-			 (mapcar (lambda (row)
-				   (and (not (eq row 'hline))
-					(mapcar #'org-babel-string-read row)))
-				 (org-table-to-lisp))))
-	       (error (message "Error reading results: %s" err) nil)))))
-      (pcase result
-	(`((,scalar)) scalar)
-	(`((,_ ,_ . ,_)) result)
-	(`(,scalar) scalar)
-	(_ result)))))
+  (let ((result
+	 (with-temp-buffer
+	   (condition-case err
+	       (progn
+		 (org-table-import file-name separator)
+		 (delete-file file-name)
+		 (delq nil
+		       (mapcar (lambda (row)
+				 (and (not (eq row 'hline))
+				      (mapcar #'org-babel-string-read row)))
+			       (org-table-to-lisp))))
+	     (error
+	      (display-warning 'org-babel
+			       (format "Error reading results: %S" err)
+			       :error)
+	      nil)))))
+    (pcase result
+      (`((,scalar)) scalar)
+      (`((,_ ,_ . ,_)) result)
+      (`(,scalar) scalar)
+      (_ result))))
 
 (defun org-babel-string-read (cell)
   "Strip nested \"s from around strings."

base-commit: 5e2490bdf29a1eeff91b631425c38309cf368690
-- 
2.26.2



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

* Re: [PATCH] ob-core: Display warning on failure to read results
  2020-05-21  4:16 ` [PATCH] ob-core: Display warning on failure to read results Kyle Meyer
@ 2020-05-21 21:55   ` Greg Minshall
  2020-05-24 16:04   ` Kyle Meyer
  1 sibling, 0 replies; 4+ messages in thread
From: Greg Minshall @ 2020-05-21 21:55 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

Kyle, thanks for the reply and for the patch.  cheers, Greg


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

* Re: [PATCH] ob-core: Display warning on failure to read results
  2020-05-21  4:16 ` [PATCH] ob-core: Display warning on failure to read results Kyle Meyer
  2020-05-21 21:55   ` Greg Minshall
@ 2020-05-24 16:04   ` Kyle Meyer
  1 sibling, 0 replies; 4+ messages in thread
From: Kyle Meyer @ 2020-05-24 16:04 UTC (permalink / raw)
  To: Greg Minshall, emacs-orgmode

Kyle Meyer writes:

> Subject: [PATCH] ob-core: Display warning on failure to read results

Applied to master (14878f3f9).


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

end of thread, other threads:[~2020-05-24 16:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-03 14:27 Bug: Code block returned no value [9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/26.3/lisp/org/)] Greg Minshall
2020-05-21  4:16 ` [PATCH] ob-core: Display warning on failure to read results Kyle Meyer
2020-05-21 21:55   ` Greg Minshall
2020-05-24 16:04   ` Kyle Meyer

Code repositories for project(s) associated with this 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).