diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 5e9d35f58..b37e3965a 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -437,24 +439,23 @@ (defun org-babel-R-evaluate-session (org-babel-import-elisp-from-file tmp-file '(16))) column-names-p))) (output - (mapconcat - 'org-babel-chomp - (butlast - (delq nil - (mapcar - (lambda (line) (when (> (length line) 0) line)) - (mapcar - (lambda (line) ;; cleanup extra prompts left in output - (if (string-match - "^\\([>+.]\\([ ][>.+]\\)*[ ]\\)" - (car (split-string line "\n"))) - (substring line (match-end 1)) - line)) - (org-babel-comint-with-output (session org-babel-R-eoe-output) - (insert (mapconcat 'org-babel-chomp - (list body org-babel-R-eoe-indicator) - "\n")) - (inferior-ess-send-input)))))) "\n")))) + (let* ((tmp-file (org-babel-temp-file "R-"))) + (with-temp-file tmp-file + (insert (concat body "\n" org-babel-R-eoe-indicator))) + (with-current-buffer session + (let* ((process (get-buffer-process (current-buffer))) + (string-buffer "") + (comint-output-filter-functions + (cons (lambda (text) (setq string-buffer + (concat string-buffer text))) + comint-output-filter-functions))) + (ess-send-string + process (format "source('%s', print.eval=TRUE)" + (org-babel-process-file-name tmp-file 'noquote))) + (while (not (string-match (regexp-quote org-babel-R-eoe-output) + string-buffer)) + (accept-process-output process)) + (substring string-buffer 0 (match-beginning 0)))))))) (defun org-babel-R-process-value-result (result column-names-p) "R-specific processing of return value.