babel: Fix temporary file processing in the remote execution case.

* ob.el (org-babel-temp-file): Don't use babel temporary
	directory in remote case; use make-temp-file with remote file
	name so that temp file is guaranteed not to exist previously
	on remote machine.
	(org-babel-tramp-localname): New function to return local name
	portion of possibly remote file specification

	* ob-R.el (org-babel-R-evaluate-external-process): Respond to
	changes in `org-babel-temp-file'; pass local file name to
	remote R process.
	(org-babel-R-evaluate-session) Respond to
	changes in `org-babel-temp-file'; pass local file name to
	remote R process.
This commit is contained in:
Dan Davison 2010-08-30 09:34:05 -07:00
parent fcfba8d487
commit 9c878a8290
2 changed files with 23 additions and 12 deletions

View File

@ -236,7 +236,7 @@ string. If RESULT-TYPE equals 'value then return the value of the
last statement in BODY, as elisp." last statement in BODY, as elisp."
(case result-type (case result-type
(value (value
(let ((tmp-file (org-babel-temp-file "R-results-"))) (let ((tmp-file (org-babel-temp-file "R-")))
(org-babel-eval org-babel-R-command (org-babel-eval org-babel-R-command
(format org-babel-R-write-object-command (format org-babel-R-write-object-command
(if row-names-p "TRUE" "FALSE") (if row-names-p "TRUE" "FALSE")
@ -244,10 +244,9 @@ last statement in BODY, as elisp."
(if row-names-p "NA" "TRUE") (if row-names-p "NA" "TRUE")
"FALSE") "FALSE")
(format "{function ()\n{\n%s\n}}()" body) (format "{function ()\n{\n%s\n}}()" body)
tmp-file)) (org-babel-tramp-localname tmp-file)))
(org-babel-R-process-value-result (org-babel-R-process-value-result
(org-babel-import-elisp-from-file (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p)))
(org-babel-maybe-remote-file tmp-file) '(16)) column-names-p)))
(output (org-babel-eval org-babel-R-command body)))) (output (org-babel-eval org-babel-R-command body))))
(defun org-babel-R-evaluate-session (defun org-babel-R-evaluate-session
@ -265,16 +264,15 @@ last statement in BODY, as elisp."
(ess-eval-buffer nil))) (ess-eval-buffer nil)))
(let ((tmp-file (org-babel-temp-file "R-"))) (let ((tmp-file (org-babel-temp-file "R-")))
(org-babel-comint-eval-invisibly-and-wait-for-file (org-babel-comint-eval-invisibly-and-wait-for-file
session (org-babel-maybe-remote-file tmp-file) session tmp-file
(format org-babel-R-write-object-command (format org-babel-R-write-object-command
(if row-names-p "TRUE" "FALSE") (if row-names-p "TRUE" "FALSE")
(if column-names-p (if column-names-p
(if row-names-p "NA" "TRUE") (if row-names-p "NA" "TRUE")
"FALSE") "FALSE")
".Last.value" tmp-file)) ".Last.value" (org-babel-tramp-localname tmp-file)))
(org-babel-R-process-value-result (org-babel-R-process-value-result
(org-babel-import-elisp-from-file (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p)))
(org-babel-maybe-remote-file tmp-file) '(16)) column-names-p)))
(output (output
(mapconcat (mapconcat
#'org-babel-chomp #'org-babel-chomp

View File

@ -1671,6 +1671,13 @@ the remote connection."
(concat "/" user (when user "@") host ":" file)) (concat "/" user (when user "@") host ":" file))
file)) file))
(defun org-babel-tramp-localname (file)
"Return the local name component of FILE."
(if (file-remote-p file)
(with-parsed-tramp-file-name file nil
localname)
file))
(defvar org-babel-temporary-directory (defvar org-babel-temporary-directory
(or (and (boundp 'org-babel-temporary-directory) (or (and (boundp 'org-babel-temporary-directory)
org-babel-temporary-directory) org-babel-temporary-directory)
@ -1684,10 +1691,16 @@ Emacs shutdown.")
Passes PREFIX and SUFFIX directly to `make-temp-file' with the Passes PREFIX and SUFFIX directly to `make-temp-file' with the
value of `temporary-file-directory' temporarily set to the value value of `temporary-file-directory' temporarily set to the value
of `org-babel-temporary-directory'." of `org-babel-temporary-directory'."
(let ((temporary-file-directory (expand-file-name (if (file-remote-p default-directory)
org-babel-temporary-directory (make-temp-file
temporary-file-directory))) (concat (file-remote-p default-directory)
(make-temp-file prefix nil suffix))) (expand-file-name
prefix temporary-file-directory)
nil suffix))
(let ((temporary-file-directory (expand-file-name
org-babel-temporary-directory
temporary-file-directory)))
(make-temp-file prefix nil suffix))))
(defun org-babel-remove-temporary-directory () (defun org-babel-remove-temporary-directory ()
"Remove `org-babel-temporary-directory' on Emacs shutdown." "Remove `org-babel-temporary-directory' on Emacs shutdown."