From 5f8a57ad48d5c9d57dbdf169d9464dbd98afc852 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 21 Feb 2010 00:16:25 -0500 Subject: [PATCH] babel: change implementation of external R process evaluation Use shell-command-on-region, bringing R into line with ruby, python, clojure, shell. In addition to consistency (and perhaps efficiency), this will also be preferable in the case of a remote R process because it means that transfer of the input to the remote process is dealt with automatically by tramp. --- contrib/babel/lisp/langs/org-babel-R.el | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/contrib/babel/lisp/langs/org-babel-R.el b/contrib/babel/lisp/langs/org-babel-R.el index ec65080da..f536dad03 100644 --- a/contrib/babel/lisp/langs/org-babel-R.el +++ b/contrib/babel/lisp/langs/org-babel-R.el @@ -141,19 +141,18 @@ BODY, if RESULT-TYPE equals 'value then return the value of the last statement in BODY, as elisp." (if (not session) ;; external process evaluation - (let ((in-tmp-file (make-temp-file "R-in-functional-results")) - (out-tmp-file (make-temp-file "R-out-functional-results"))) + (let ((tmp-file (make-temp-file "R-out-functional-results"))) (case result-type (output - (with-temp-file in-tmp-file (insert body)) - (shell-command-to-string (format "R --slave --no-save < '%s' > '%s'" - in-tmp-file out-tmp-file)) - (with-temp-buffer (insert-file-contents out-tmp-file) (buffer-string))) + (with-temp-buffer + (insert body) + (shell-command-on-region (point-min) (point-max) "R --slave --no-save" 'replace) + (buffer-string))) (value - (with-temp-file in-tmp-file + (with-temp-buffer (insert (format org-babel-R-wrapper-method - body out-tmp-file (if column-names-p "TRUE" "FALSE")))) - (shell-command (format "R --no-save < '%s'" in-tmp-file)) + body tmp-file (if column-names-p "TRUE" "FALSE"))) + (shell-command-on-region (point-min) (point-max) "R --no-save" 'replace)) (org-babel-R-process-value-result (org-babel-import-elisp-from-file out-tmp-file) column-names-p)))) ;; comint session evaluation