Run a remote R session in emacs: emacs + ESS + R + ssh

I don’t know how, but somehow, I stumbled on how to run a remote R session in emacs.

Since Spring 2006 I’ve always used emacs with ESS to run R (did it on windows, switched to linux for years, and most recently, on my macbook). I liked this workflow because I get the same usual interface across multiple platforms. Plus, I use emacs for everything computery or scientific, like using coding Python or C.

Regarding the same interface across multiple platforms, I use, for example, emacs + ESS + R whenever I remotely log into the remote servers dedicated to computing. I just need to ssh into the server, fire up emacs and fire up R. However, I almost always write all of my code on the local computer, and when I’m ready to run the final code, I either run it as a batch script (utlizing nohup and &), through screen (to keep the session runnning after I log out, see my post on R with unix tools), or through emacs. These days, I’ve been doing it with screen mainly so disconnects to the server won’t interrupt my script.

I just found yet another way to do this: write code on my local computer and then send code to a remote R session in my local emacs. I ran into this by googling ‘emacs ess multiple R session’. Instructions are described here (section 3.3: ESS on remote computers). We need this file for things to work. This site clarified how to get graphics to work.

Instructions as follow:

  1. Download the ssh.el file.
  2. Install it the usual way or place it in ~/elisp or ~/.emacs.d. In your emacs init file, add:
 <pre class="src src-sh">;; add path to emacs

;; http://edward.oconnor.cx/2005/09/installing-elisp-files (add-to-list ‘load-path “~/elisp”)

;; load ssh.el file from elisp ;; this is to run ESS remotely on another computer in my own emacs, or just plai n old reading remote files ;; (require ‘ssh)

  1. Fire up emacs. Type ‘M-x ssh’. For the host settings, do something like ‘-X -C username@server.com’ (X is for X windows forwarding, C is for compression of graphics, so plots can be displayed faster). Type in password.
  2. You wil be logged into a shell session on your server. Fire up R by typing R then enter. R is now running in an emacs buffer. Type M-x ess-remote. For dialect, select r.
  3. Open up any .R file on your computer, and use the usual keyboard shortcuts to send code to the remote R session.

W can also achieve the same results without the ssh.el file. In emacs, type M-x shell. In the shell buffer, ssh into the server and then run R. Type M-x ess-remote and everything should still work.

Next thing to get working is to open remote files in my local emacs.

About Vinh Nguyen

Statistician

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>