emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Sebastien Vauban <wxhgmqzgwmuf@spammotel.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [babel] Specified colnames
Date: Mon, 08 Apr 2013 10:41:44 -0600	[thread overview]
Message-ID: <87obdp0ybb.fsf@gmail.com> (raw)
In-Reply-To: <86y5cuxfro.fsf@somewhere.org> (Sebastien Vauban's message of "Sun, 07 Apr 2013 22:11:23 +0200")

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

"Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> writes:

> Hi Eric,
>
> I'm trying to specify the column names of the table.
>
> #+name: input
> | title | baz |
> |-------+-----|
> | obs1  | foo |
> | obs2  | bar |
>
> But both versions (with symbols or strings) just do return the plain input
> table.
>
> #+name: R-echo-colnames-list
> #+begin_src R :var data=input :exports results :colnames '(Rev Author)
> data
> #+end_src
>
> #+name: R-echo-colnames-qlist
> #+begin_src R :var data=input :exports results :colnames '("Rev" "Author")
> data
> #+end_src
>
> Am I doing something wrong?
>
> Best regards,
>   Seb

It looks like ob-R implements its own result table reconstruction
instead of using the general support.  This is because R actually has a
notion of column names and row names internally.  The implementation in
ob-R does not correctly handle specified colnmaes as your example shows.

The attached patch brings ob-R closer to the using the unified general
table reconstructed used in most other languages, and fixes your problem
mentioned above.  I haven't applied it however, as it may introduce
other bugs related to specifying column names from within R.  For
example, I'm not sure that it will now correctly apply column names from
a table built entirely from within R.

Additional testing by someone more familiar with R than myself would be
greatly appreciated.

Thanks,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-use-org-babel-reassemble-table-in-ob-R.patch --]
[-- Type: text/x-patch, Size: 3403 bytes --]

From 680bfe22c423d5fad43348fc86eba6618f3aa57c Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Mon, 8 Apr 2013 10:36:32 -0600
Subject: [PATCH] use org-babel-reassemble-table in ob-R

* lisp/ob-R.el (org-babel-execute:R): Use org-babel-reassemble-table to
  reconstruct tables with column and row names.
  (org-babel-R-evaluate-external-process): Don't use R-specific table
  reconstruction.
  (org-babel-R-evaluate-session): Don't use R-specific table
  reconstruction.
---
 lisp/ob-R.el | 46 ++++++++++++++++++----------------------------
 1 file changed, 18 insertions(+), 28 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 67d3c37..b424f0f 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -111,13 +111,14 @@ This function is called by `org-babel-execute-src-block'."
 	   (result
 	    (org-babel-R-evaluate
 	     session full-body result-type result-params
-	     (or (equal "yes" colnames-p)
-		 (org-babel-pick-name
-		  (cdr (assoc :colname-names params)) colnames-p))
-	     (or (equal "yes" rownames-p)
-		 (org-babel-pick-name
-		  (cdr (assoc :rowname-names params)) rownames-p)))))
-      (if graphics-file nil result))))
+	     (equal "yes" colnames-p) (equal "yes" rownames-p))))
+      (if graphics-file nil
+	(org-babel-reassemble-table
+	 result
+	 (org-babel-pick-name (cdr (assoc :colname-names params))
+			      (cdr (assoc :colnames params)))
+	 (org-babel-pick-name (cdr (assoc :rowname-names params))
+			      (cdr (assoc :rownames params))))))))
 
 (defun org-babel-prep-session:R (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
@@ -301,13 +302,11 @@ last statement in BODY, as elisp."
 				 "FALSE")
 			       (format "{function ()\n{\n%s\n}}()" body)
 			       (org-babel-process-file-name tmp-file 'noquote)))
-       (org-babel-R-process-value-result
-	(org-babel-result-cond result-params
-	  (with-temp-buffer
-	    (insert-file-contents tmp-file)
-	    (buffer-string))
-	  (org-babel-import-elisp-from-file tmp-file '(16)))
-	column-names-p)))
+       (org-babel-result-cond result-params
+	 (with-temp-buffer
+	   (insert-file-contents tmp-file)
+	   (buffer-string))
+	 (org-babel-import-elisp-from-file tmp-file '(16)))))
     (output (org-babel-eval org-babel-R-command body))))
 
 (defun org-babel-R-evaluate-session
@@ -333,13 +332,11 @@ last statement in BODY, as elisp."
 		    (if row-names-p "NA" "TRUE")
 		  "FALSE")
 		".Last.value" (org-babel-process-file-name tmp-file 'noquote)))
-       (org-babel-R-process-value-result
-	(org-babel-result-cond result-params
-	  (with-temp-buffer
-	    (insert-file-contents tmp-file)
-	    (buffer-string))
-	  (org-babel-import-elisp-from-file tmp-file '(16)))
-	column-names-p)))
+       (org-babel-result-cond result-params
+	 (with-temp-buffer
+	   (insert-file-contents tmp-file)
+	   (buffer-string))
+	 (org-babel-import-elisp-from-file tmp-file '(16)))))
     (output
      (mapconcat
       #'org-babel-chomp
@@ -359,13 +356,6 @@ last statement in BODY, as elisp."
 				    "\n"))
 		 (inferior-ess-send-input)))))) "\n"))))
 
-(defun org-babel-R-process-value-result (result column-names-p)
-  "R-specific processing of return value.
-Insert hline if column names in output have been requested."
-  (if column-names-p
-      (cons (car result) (cons 'hline (cdr result)))
-    result))
-
 (provide 'ob-R)
 
 
-- 
1.8.2


[-- Attachment #3: Type: text/plain, Size: 46 bytes --]


-- 
Eric Schulte
http://cs.unm.edu/~eschulte

  reply	other threads:[~2013-04-08 16:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-07 20:11 [babel] Specified colnames Sebastien Vauban
2013-04-08 16:41 ` Eric Schulte [this message]
2013-04-08 19:45   ` Sebastien Vauban
2013-04-08 20:15     ` Eric Schulte
2013-04-08 20:49       ` Sebastien Vauban
2013-04-12 21:42         ` Eric Schulte
2013-04-18 21:25           ` Sebastien Vauban
2013-04-20 10:11             ` Eric Schulte
2013-04-25 13:28               ` Sebastien Vauban
2013-04-27 15:02                 ` Eric Schulte
2013-04-27 16:06                   ` Sebastien Vauban
2013-04-27 16:47                     ` Eric Schulte

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=87obdp0ybb.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=wxhgmqzgwmuf@spammotel.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).