Search code examples
remacssshesstramp

Run remote R process using script on local machine


I use R in Debian with emacs and ess. I would run an R process on a remote machine from an R script in my laptop. So from within emacs load my R script, I ssh to the remote machine and start a new R session, than I use M-x ess-remote to connect the remote R process to my local R script. All works well until I try to load some function from my laptop (local machine) and send it to the remote R. Whenever I try to do this I get the following error:

source('myFunction.R')
Error in file(filename, "r", encoding = encoding) : 
  cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
  cannot open file 'myFunction.R': No such file or directory

If I switch to the R console and I getwd() the console says that I am in the home directory of the remote machine.

I followed the instruction from the ess wbb-site here. Where do I wrong?


Solution

  • What I do in this case is open the local file in Emacs and then,

    M-x ess-eval-buffer
    

    This will take the contents of you file and evaluate it on the remote connection.

    Another option is to move your scripts to the remote machine and open them remotely with tramp. Then you can edit them locally and use all that ESS has to offer. This second option will allow you to use source as in your question.

    A short cut for opening the remote script is to select the *R* buffer then C-x C-f to open a file.

    I hope this helps.