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