Browse Source

generalizing command to read results from a file into elisp

Eric Schulte 16 years ago
parent
commit
8620cc414c
2 changed files with 22 additions and 17 deletions
  1. 1 16
      lisp/org-babel-R.el
  2. 21 1
      lisp/org-babel.el

+ 1 - 16
lisp/org-babel-R.el

@@ -93,22 +93,7 @@ R process in `org-babel-R-buffer'."
      org-babel-R-buffer
      (format "write.table(.Last.value, file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=FALSE, quote=FALSE)"
              tmp-file))
-    (with-temp-buffer
-      (condition-case nil
-          (progn
-            (org-table-import tmp-file nil)
-            (delete-file tmp-file)
-            (setq result (mapcar (lambda (row)
-                                   (mapcar #'org-babel-R-read row))
-                                 (org-table-to-lisp))))
-        (error nil))
-      (if (null (cdr result)) ;; if result is trivial vector, then scalarize it
-          (if (consp (car result))
-              (if (null (cdr (car result)))
-                  (caar result)
-                result)
-            (car result))
-        result))))
+    (org-babel-import-elisp-from-file tmp-file)))
 
 (defun org-babel-R-read (cell)
   "Strip nested \"s from around strings in exported R values."

+ 21 - 1
lisp/org-babel.el

@@ -72,7 +72,7 @@ then run `org-babel-execute-src-block'."
 `org-babel-src-block-regexp' appropriately."
   (unless (member interpreter org-babel-interpreters)
     (setq org-babel-interpreters (cons interpreter org-babel-interpreters))
-    (add-to-list 'org-babel-session-defaults (cons interpreter (format "org-babel-%s" interpreter)))
+    ;; (add-to-list 'org-babel-session-defaults (cons interpreter (format "org-babel-%s" interpreter)))
     (org-babel-set-interpreters 'org-babel-interpreters org-babel-interpreters)))
 
 (defcustom org-babel-interpreters '()
@@ -359,6 +359,26 @@ This is taken almost directly from `org-read-prop'."
   "Return t if STRING represents a number"
   (string-match "^[[:digit:]]*\\.?[[:digit:]]*$" string))
 
+(defun org-babel-import-elisp-from-file (file-name)
+  "Read the results located at FILE-NAME into an elisp table.  If
+the table is trivial, then return it as a scalar."
+  (with-temp-buffer
+    (condition-case nil
+        (progn
+          (org-table-import file-name nil)
+          (delete-file file-name)
+          (setq result (mapcar (lambda (row)
+                                 (mapcar #'org-babel-R-read row))
+                               (org-table-to-lisp))))
+      (error nil))
+    (if (null (cdr result)) ;; if result is trivial vector, then scalarize it
+        (if (consp (car result))
+            (if (null (cdr (car result)))
+                (caar result)
+              result)
+          (car result))
+      result)))
+
 (defun org-babel-reverse-string (string)
   (apply 'string (reverse (string-to-list string))))