From ed688ed93866dc083424a5ae1577aac8d56f405b Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Thu, 3 Sep 2009 11:47:32 -0400 Subject: [PATCH] Rearrange R evaluation code so that .Last.value evaluated in :results value case only One example of a problem that crops up without this is a block like f <- function(x) x without this change, in :results output mode, we make an attempt to coerce .Last.value (a function) to a data frame, which throws an error. --- lisp/langs/org-babel-R.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lisp/langs/org-babel-R.el b/lisp/langs/org-babel-R.el index 4e0b2a858..1ef21db22 100644 --- a/lisp/langs/org-babel-R.el +++ b/lisp/langs/org-babel-R.el @@ -117,12 +117,17 @@ last statement in BODY, as elisp." ;; comint session evaluation (org-babel-comint-in-buffer buffer (let* ((tmp-file (make-temp-file "org-babel-R")) - (last-value-eval - (format "write.table(.Last.value, file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=%s, quote=FALSE)" tmp-file (if column-names-p "TRUE" "FALSE"))) - (full-body (mapconcat #'org-babel-chomp - (list body last-value-eval org-babel-R-eoe-indicator) "\n")) - (raw (org-babel-comint-with-output buffer org-babel-R-eoe-output nil - (insert full-body) (inferior-ess-send-input))) broke results) + (full-body + (case result-type + (value + (mapconcat #'org-babel-chomp (list body + (format "write.table(.Last.value, file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=%s, quote=FALSE)" tmp-file (if column-names-p "TRUE" "FALSE")) + org-babel-R-eoe-indicator) "\n")) + (output + (mapconcat #'org-babel-chomp (list body org-babel-R-eoe-indicator) "\n")))) + (raw (org-babel-comint-with-output buffer org-babel-R-eoe-output nil + (insert full-body) (inferior-ess-send-input))) + broke results) (case result-type (value (org-babel-R-process-value-result (org-babel-import-elisp-from-file tmp-file) column-names-p))