From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel] Specified colnames Date: Mon, 08 Apr 2013 10:41:44 -0600 Message-ID: <87obdp0ybb.fsf@gmail.com> References: <86y5cuxfro.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:51141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPF9c-0004Ku-HN for emacs-orgmode@gnu.org; Mon, 08 Apr 2013 12:42:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPF9X-0008WG-2G for emacs-orgmode@gnu.org; Mon, 08 Apr 2013 12:42:48 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:33364) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPF9W-0008W7-P0 for emacs-orgmode@gnu.org; Mon, 08 Apr 2013 12:42:42 -0400 Received: by mail-pa0-f50.google.com with SMTP id bg2so3335365pad.9 for ; Mon, 08 Apr 2013 09:42:41 -0700 (PDT) In-Reply-To: <86y5cuxfro.fsf@somewhere.org> (Sebastien Vauban's message of "Sun, 07 Apr 2013 22:11:23 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Sebastien Vauban Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain "Sebastien Vauban" 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, --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-use-org-babel-reassemble-table-in-ob-R.patch >From 680bfe22c423d5fad43348fc86eba6618f3aa57c Mon Sep 17 00:00:00 2001 From: Eric Schulte 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 --=-=-= Content-Type: text/plain -- Eric Schulte http://cs.unm.edu/~eschulte --=-=-=--