Hi Chuck, > This does not work for my remote session. Thanks for testing this. The remote tests I originally tried did not cover this case -- I only tested the case where both org-file and session were remote, but didn't test the case where org-file was local and session was remote. I've now tested this case as well, and added some fixes for it. I'm reattaching the patch in full. However, this implementation does require the R session to have the correct default-directory -- see details below. > The problem is that tempfiles on the remote host are like "/tmp/RtmpeFHudh/file23a66d2fc1f9", but emacs tries to use '/var/folders/kb/2hchpbyj7lb6z76l0q73w_fh0000gn/T/babel-OSXKNd/R-oNOVVB' > > `org-babel-temp-file' doesn't honor remote connections AFAICS. org-babel-temp-file does honor remote connections, but relies on default-directory to do so. I've moved the call to org-babel-temp-file so it happens when the session buffer is current -- that way, the tempfile will be correctly handled, assuming that the session's default-directory is on the remote location. If the session's default-directory isn't at the remote location, then this will break. But, in this case some other things break as well, for example inserting links to remote plots. > Maybe there is some comint or tramp idiom that would solve this, but I do not know what it is. Here are some ways to start a remote R session with correct default-directory: 1. Do "M-x R", then when it prompts for a directory, use "/scp:hostname:/some/path". Optionally, first visit that location with "C-x C-f /scp:hostname:/some/path", so that the default value is already there. 2. Alternatively, start the R session by evaluating a source block with header argument ":dir /scp:hostname:/some/path". 3. If you prefer to use "M-x shell" with "ess-remote", first visit the remote location with "C-x C-f /scp:hostname:/some/path", before calling "M-x shell". 4. If you prefer to start "M-x shell" locally and then ssh in, it's still possible to have default-directory set, but it requires some configuration [1]. Or you could use "M-x cd" to set it as well. [1] https://emacs.stackexchange.com/questions/5589/automatically-update-default-directory-when-pwd-changes-in-shell-mode-and-term-m/5592#5592 Best, Jack