From a39d68640e3fbc059f3b05c9eafc8bf07cc4b51d Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 30 May 2009 15:00:06 -0400 Subject: [PATCH] Allowing org-tables with hline to be referred to and passed into R. If hline is present, the first row of the table becomes the column names in R. This allows the grades example to run for me which was not true before. Eric: any commits I make should be viewed as tentative -- feel free to reject or recode them. --- lisp/org-babel-R.el | 17 ++++++++++------- lisp/org-babel-ref.el | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lisp/org-babel-R.el b/lisp/org-babel-R.el index 69743d3d4..70087e191 100644 --- a/lisp/org-babel-R.el +++ b/lisp/org-babel-R.el @@ -62,13 +62,16 @@ R process in `org-babel-R-buffer'." (unless org-babel-R-buffer (error "No active R buffer")) (org-babel-R-input-command (if (listp value) - (let ((transition-file (make-temp-file "org-babel-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\", sep=\"\\t\", as.is=TRUE)" name transition-file)) + (let ((transition-file (make-temp-file "org-babel-R-import")) + has-header) + ;; ensure VALUE has an orgtbl structure (depth of at least 2) + (unless (listp (car value)) (setq value (list value))) + (setq has-header (and (symbolp (cadr value)) (equal (cadr value) 'hline))) + (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, sep=\"\\t\", as.is=TRUE)" + name transition-file (if has-header "TRUE" "FALSE"))) (format "%s <- %s" name (org-babel-R-quote-tsv-field value))))) (defun org-babel-R-to-elisp (func-name) diff --git a/lisp/org-babel-ref.el b/lisp/org-babel-ref.el index 9af1e8f0f..b41dea656 100644 --- a/lisp/org-babel-ref.el +++ b/lisp/org-babel-ref.el @@ -128,7 +128,8 @@ return nil." (case type ('table (mapcar (lambda (row) - (mapcar #'org-babel-read row)) + (if (and (symbolp row) (equal row 'hline)) row + (mapcar #'org-babel-read row))) (org-table-to-lisp))) ('source-block (setq result (org-babel-execute-src-block t nil args))