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

[This article was first published on Super Nerdy Cool » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I don’t know how, but somehow, i stumbled on how to do this.

I’ve always used emacs with ESS to run R, since spring 2006 (did it on windows, switched to linux, for years, and most recently, on my macbook). I liked this because i get the same usual interface across ALL platforms (well, maybe not on an MVS mainframe, but i’ve never even seen R on one of those things). Plus, i use emacs for everything computery and/or scientific, like using python or code in C (well, i hope to do more of this (do i really hope to?)).

Regarding the same interface across all platforms, i use, for example, emacs + ESS + R whenever i remotely log into the ics servers at uci (well, at least anything computationally intensive). So i ssh into it, fire up emacs, fire up R. Been doing this since whenever. Thing is, I usually always write my code on my local computer, and when i’m ready to run the final code, i either run it as a batch script (‘nohup’, and with ‘&’), through the ‘screen’ command (to keep the session runnning when 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.

Well, I just found yet another way to do this: write code on local computer, send code to R session easily in emacs (ie not copy and paste). Oh I remember now, I ran into this by googling ‘emacs ess multiple R session’.

Go here, go to section 3.3, ESS on remote computers. We will need this file. This site clarified how to get graphics to show.

Instruction is as follows.

  1. download the ssh.el file.
  2. install it your usual way. or, for example, place it in ~/elisp. In your .emacs file, add:
;; 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 host, do something like ‘-X -C [email protected]’ (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 of your server. Fire up R, by typing R then enter. R is now running one of your emacs buffer. type ‘M-x ess-remote’. For dialect, select ‘r’.
  3. open up any *.R file on your computer, and use the usual hot keys to send them to remote R session.

This is super cool huh?!?! I like! Alternatively, we can do the same without the ssh.el file. In emacs, hit ‘M-x shell’. In this shell, do your ssh -X -C stuff, then run R. Do ‘M-x ess-remote’ and everything should still work!

Next thing to do, with my local emacs, open files that are remote. this should be easy i think.

To leave a comment for the author, please follow the link and comment on their blog: Super Nerdy Cool » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)