From: "Eric Schulte" <schulte.eric@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [BUG][babel] ":result output table" doesn't work for python code blocks
Date: Fri, 15 Apr 2011 10:13:40 -0600 [thread overview]
Message-ID: <877hava3d8.fsf@gmail.com> (raw)
In-Reply-To: 87hb9zyf79.fsf@ucl.ac.uk
[-- Attachment #1: Type: text/plain, Size: 1070 bytes --]
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> "Eric Schulte" <schulte.eric@gmail.com> writes:
>
> [...]
>
>> That said, I agree that in examples like yours above the returned value
>> should be a table given that the ":results table" is explicitly stated.
>> I've just pushed up a patch after which the following is possible.
>
> Eric,
>
> It would appear that this change you've made is only for python)? Is
> there any chance of having the same for octave, please? But only if it
> is easy to do as =:results output raw= with carefully formatted output
> does the job for me for the moment!
>
Hi Eric,
I do not have a local copy of octave, so I'm less confident making
changes to that file, but the attached patch attempts to make the same
changes in ob-octave which were made in ob-python.
Could you please test this patch for both external and session based
evaluation and let me know if it works (I'm more hopeful that the
external evaluation will work as expected than the session evaluation).
Once this is working I'll commit it to the core.
Thanks -- Eric
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-octave-allow-collecting-tabular-results-when-resu.patch --]
[-- Type: text/x-diff, Size: 3905 bytes --]
From 7477c3ac10d28342ccf993ea36b41ebfcab015ac Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Fri, 15 Apr 2011 10:11:18 -0600
Subject: [PATCH] ob-octave: allow collecting tabular results when ":results output"
* lisp/ob-octave.el (org-babel-octave-evaluate-external-process): Dump
output to temp file, and read results from that file as with ":results value".
(org-babel-octave-evaluate-session): Read results from temporary
file with both ":results output" and ":results value".
---
lisp/ob-octave.el | 55 ++++++++++++++++++++++++++++------------------------
1 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 3430dea..064677e 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -164,18 +164,18 @@ value of the last statement in BODY, as elisp."
(defun org-babel-octave-evaluate-external-process (body result-type matlabp)
"Evaluate BODY in an external octave process."
- (let ((cmd (if matlabp
+ (let ((tmp-file (org-babel-temp-file "octave-"))
+ (cmd (if matlabp
org-babel-matlab-shell-command
org-babel-octave-shell-command)))
(case result-type
- (output (org-babel-eval cmd body))
- (value (let ((tmp-file (org-babel-temp-file "octave-")))
- (org-babel-eval
- cmd
- (format org-babel-octave-wrapper-method body
- (org-babel-process-file-name tmp-file 'noquote)
- (org-babel-process-file-name tmp-file 'noquote)))
- (org-babel-octave-import-elisp-from-file tmp-file))))))
+ (output (with-temp-file tmp-file (insert (org-babel-eval cmd body))))
+ (value (org-babel-eval
+ cmd
+ (format org-babel-octave-wrapper-method body
+ (org-babel-process-file-name tmp-file 'noquote)
+ (org-babel-process-file-name tmp-file 'noquote)))))
+ (org-babel-octave-import-elisp-from-file tmp-file)))
(defun org-babel-octave-evaluate-session
(session body result-type &optional matlabp)
@@ -194,7 +194,8 @@ value of the last statement in BODY, as elisp."
(format org-babel-matlab-emacs-link-wrapper-method
body
(org-babel-process-file-name tmp-file 'noquote)
- (org-babel-process-file-name tmp-file 'noquote) wait-file) "\n")
+ (org-babel-process-file-name tmp-file 'noquote)
+ wait-file) "\n")
(mapconcat
#'org-babel-chomp
(list (format org-babel-octave-wrapper-method
@@ -221,21 +222,25 @@ value of the last statement in BODY, as elisp."
org-babel-octave-eoe-output)
t full-body)
(insert full-body) (comint-send-input nil t)))) results)
- (case result-type
- (value
- (org-babel-octave-import-elisp-from-file tmp-file))
- (output
- (progn
- (setq results
- (if matlabp
- (cdr (reverse (delq "" (mapcar
- #'org-babel-octave-read-string
- (mapcar #'org-babel-trim raw)))))
- (cdr (member org-babel-octave-eoe-output
- (reverse (mapcar
- #'org-babel-octave-read-string
- (mapcar #'org-babel-trim raw)))))))
- (mapconcat #'identity (reverse results) "\n"))))))
+ (if (or (member "code" result-params)
+ (member "pp" result-params)
+ (member "scalar" result-params)
+ (and (member "output" result-params)
+ (not (member "table" result-params))))
+ (progn
+ (setq results
+ (if matlabp
+ (cdr (reverse (delq "" (mapcar
+ #'org-babel-octave-read-string
+ (mapcar #'org-babel-trim raw)))))
+ (cdr (member org-babel-octave-eoe-output
+ (reverse (mapcar
+ #'org-babel-octave-read-string
+ (mapcar #'org-babel-trim raw)))))))
+ (mapconcat #'identity (reverse results) "\n"))
+ (when (equal results-type 'output)
+ (with-temp-file tmp-file (insert raw)))
+ (org-babel-octave-import-elisp-from-file tmp-file))))
(defun org-babel-octave-import-elisp-from-file (file-name)
"Import data from FILE-NAME.
--
1.7.1
[-- Attachment #3: Type: text/plain, Size: 47 bytes --]
--
Eric Schulte
http://cs.unm.edu/~eschulte/
next prev parent reply other threads:[~2011-04-15 16:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-15 0:46 [BUG][babel] ":result output table" doesn't work for python code blocks Ethan Ligon
2011-04-15 2:26 ` Eric Schulte
2011-04-15 10:35 ` Eric S Fraga
2011-04-15 16:13 ` Eric Schulte [this message]
2011-04-20 20:28 ` Eric S Fraga
2011-04-26 19:31 ` Eric Schulte
2011-04-27 10:09 ` Eric S Fraga
2011-04-27 13:16 ` Eric Schulte
2011-04-27 15:28 ` Eric S Fraga
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=877hava3d8.fsf@gmail.com \
--to=schulte.eric@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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).