From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Babel: communicating irregular data to R source-code block Date: Mon, 23 Apr 2012 17:05:40 -0400 Message-ID: <87vckqtazf.fsf@gmx.com> References: <1335039472.9075.YahooMailNeo@web161901.mail.bf1.yahoo.com> <87ipgrn4by.fsf@gmx.com> <1335219898.41851.YahooMailNeo@web161901.mail.bf1.yahoo.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:58221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SMSKV-0005fj-Tl for emacs-orgmode@gnu.org; Mon, 23 Apr 2012 19:06:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SMSKT-0007iO-Ja for emacs-orgmode@gnu.org; Mon, 23 Apr 2012 19:05:59 -0400 Received: from mailout-us.gmx.com ([74.208.5.67]:53174 helo=mailout-us.mail.com) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SMSKT-0007hq-AW for emacs-orgmode@gnu.org; Mon, 23 Apr 2012 19:05:57 -0400 In-Reply-To: <1335219898.41851.YahooMailNeo@web161901.mail.bf1.yahoo.com> (Michael Hannon's message of "Mon, 23 Apr 2012 15:24:58 -0700 (PDT)") 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: Michael Hannon Cc: Org-Mode List , "Thomas S. Dye" --=-=-= Content-Type: text/plain [...] > > I.e.,it seems that Org is going to do its own "read.table" before even > looking at the code in the source block. > Yes, this is true, Org will use read.table to read in tabular data. See the code in lisp/ob-R.el for specifics. > > Is there some way to get Org to use the "fill=TRUE" option on a case-by-case > basis? > Yes, The attached patch allows the :fill header argument to be specified adding "fill=TRUE" to the read.table function call. Please try it out and let me know if it works for you. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-add-fill-header-argument-to-R-code-blocks.patch >From 45240d367eb981a93f3c694946d4f2a99044cda5 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 23 Apr 2012 17:04:37 -0400 Subject: [PATCH] add :fill header argument to R code blocks * lisp/ob-R.el (org-babel-header-args:R): List this as a viable R header argument. (org-babel-variable-assignments:R): Check the value of this new :fill header argument. (org-babel-R-assign-elisp): Set "fill=TRUE" if the :fill header argument has been used. --- lisp/ob-R.el | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 9538dc4..1427641 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -61,6 +61,7 @@ (colormodel . :any) (useDingbats . :any) (horizontal . :any) + (fill . ((yes no))) (results . ((file list vector table scalar verbatim) (raw org html latex code pp wrap) (replace silent append prepend) @@ -148,7 +149,8 @@ This function is called by `org-babel-execute-src-block'." (org-babel-R-assign-elisp (car pair) (cdr pair) (equal "yes" (cdr (assoc :colnames params))) - (equal "yes" (cdr (assoc :rownames params))))) + (equal "yes" (cdr (assoc :rownames params))) + (equal "yes" (cdr (assoc :fill params))))) (mapcar (lambda (i) (cons (car (nth i vars)) @@ -164,19 +166,26 @@ This function is called by `org-babel-execute-src-block'." (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"") (format "%S" s))) -(defun org-babel-R-assign-elisp (name value colnames-p rownames-p) +(defun org-babel-R-assign-elisp (name value colnames-p rownames-p fill-p) "Construct R code assigning the elisp VALUE to a variable named NAME." (if (listp value) - (let ((transition-file (org-babel-temp-file "R-import-"))) - ;; ensure VALUE has an orgtbl structure (depth of at least 2) - (unless (listp (car value)) (setq value (list value))) - (with-temp-file transition-file - (insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) - (insert "\n")) - (format "%s <- read.table(\"%s\", header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE)" - name (org-babel-process-file-name transition-file 'noquote) - (if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE") - (if rownames-p "1" "NULL"))) + (flet ((R-bool (bool) (if bool "TRUE" "FALSE"))) + (let ((transition-file (org-babel-temp-file "R-import-"))) + ;; ensure VALUE has an orgtbl structure (depth of at least 2) + (unless (listp (car value)) (setq value (list value))) + (with-temp-file transition-file + (insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) + (insert "\n")) + (format "%s <- read.table(\"%s\", %s, as.is=TRUE)" + name (org-babel-process-file-name transition-file 'noquote) + (mapconcat (lambda (pair) (concat (car pair) "=" (cdr pair))) + `(("header" . ,(R-bool (or (eq (nth 1 value) + 'hline) + colnames-p))) + ("row.names" . ,(if rownames-p "1" "NULL")) + ("sep" . "\"\\t\"") + ("fill" . ,(R-bool fill-p))) + ", ")))) (format "%s <- %s" name (org-babel-R-quote-tsv-field value)))) (defvar ess-ask-for-ess-directory nil) -- 1.7.10 --=-=-= Content-Type: text/plain Best, -- Eric Schulte http://cs.unm.edu/~eschulte/ --=-=-=--