Explorar el Código

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.

Dan Davison hace 16 años
padre
commit
a39d68640e
Se han modificado 2 ficheros con 12 adiciones y 8 borrados
  1. 10 7
      lisp/org-babel-R.el
  2. 2 1
      lisp/org-babel-ref.el

+ 10 - 7
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)

+ 2 - 1
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))