Friday, November 19, 2010

Running R on remote computer via local emacs

Aquamacs in Mac OS X and Emacs in Linux/unix can be used to edit remote (and local) R code and submit pieces of code to a remote R session. For this to work you need to install ess for emacs (Aquamacs comes with ess by default now, I don't know about emacs). If you don't have ess, you can install following this recipe.

open an R script using emacs, you can open remote files using TRAMP. You need to do C-x C-f and enter the remote location as ". After you opened your remote R script, now you have to start a remote R session. First, we need to ssh to remote host from Emacs/Aquamacs using the following commands.

M-x ssh #after this you need to enter your username, remote host and you will be prompted your password

R #start R
M-x ess-remote #after starting R, you need to start and ess-remote session,
so your R script and R session is connected.

Now you can edit your remote script and also send code to your remote R session from
your script. If you can't ssh from Emacs/Aquamacs you will need to install ssh.el. 
First prepare a .emacs file, put it in your home folder. Also, make .emacs.d folder 
your home directory. You will put the  .el files in this directory.
------contents of .emacs  file -----------

(setq load-path

      (cons "/home/username/.emacs.d" load-path))

(require 'tramp)

(require 'ssh)

(require 'password-cache)

(setq password-cache-expiry nil)

------- end of .emacs file -----------------------

in .emacs.d directory, put the following files


and this one you need so TRAMP doesn't ask password every time you save a

With the recent versions of Aquamacs (Emacs on OS X) and possibly Emacs, I can do M-x shell, to get on to the shell and ssh to the remote server. Then, I use TRAMP via C-x C-f / to open the remote file in another tab. Then, finally use,M-x ess-remote. and everything works as expected. I can pass the code in the R file to R session. 


  1. Hi, Is it possible to do this on a Windows PC?

    1. When I do M-x ssh it tells Pseudo-terminal will not be allocated because stdin is not a terminal. Couldn't find a solution anywhere.

  2. BlueHost is ultimately the best website hosting provider for any hosting services you require.