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.

This commit is contained in:
Dan Davison 2009-05-30 15:00:06 -04:00
parent 2ca59eaa0f
commit a39d68640e
2 changed files with 12 additions and 8 deletions

View File

@ -62,13 +62,16 @@ R process in `org-babel-R-buffer'."
(unless org-babel-R-buffer (error "No active R buffer")) (unless org-babel-R-buffer (error "No active R buffer"))
(org-babel-R-input-command (org-babel-R-input-command
(if (listp value) (if (listp value)
(let ((transition-file (make-temp-file "org-babel-R-import"))) (let ((transition-file (make-temp-file "org-babel-R-import"))
;; ensure VALUE has an orgtbl structure (depth of at least 2) has-header)
(unless (listp (car value)) (setq value (list value))) ;; ensure VALUE has an orgtbl structure (depth of at least 2)
(with-temp-file transition-file (unless (listp (car value)) (setq value (list value)))
(insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) (setq has-header (and (symbolp (cadr value)) (equal (cadr value) 'hline)))
(insert "\n")) (with-temp-file transition-file
(format "%s <- read.table(\"%s\", sep=\"\\t\", as.is=TRUE)" name 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))))) (format "%s <- %s" name (org-babel-R-quote-tsv-field value)))))
(defun org-babel-R-to-elisp (func-name) (defun org-babel-R-to-elisp (func-name)

View File

@ -128,7 +128,8 @@ return nil."
(case type (case type
('table ('table
(mapcar (lambda (row) (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))) (org-table-to-lisp)))
('source-block ('source-block
(setq result (org-babel-execute-src-block t nil args)) (setq result (org-babel-execute-src-block t nil args))