Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I launch an x-window from emacs ess when running R on a server?

Tags:

emacs

r

x11

ess

I am using emacs-snapshot with the ssh.el package, following the instructions from the ess manual.

There are a few ways to open an R session, but this is how I do it:

  1. open emacs
  2. C-x C-f /server:dir/file.R this puts me in ESS [S] mode
  3. Type 'plot(1)'
  4. C-c C-n to run
  5. emacs asks for starting directory, and I choose the /server:dir/
  6. I would like for a figure to pop up but it wont.

This also doesn't work when using ess-remote in shell or tramp mode, but it does work if I set the starting directory to my local desktop.

Any advice much appreciated. My current workaround is to print the file to pdf and then open pdf in DocView mode, but this takes a few extra steps and is slow.

like image 381
David LeBauer Avatar asked Nov 10 '10 23:11

David LeBauer


2 Answers

I do it the other way around:

  • ssh -X some.server.com to connect to a remote server with x11 forwarding.

  • emacsclient -nw to restart an Emacs session that is already running

  • plot(cumsum(rnorm(100))) in R as usual

Then the plot windows appears on the initial machine I ssh'ed away from.

Edit: As a follow-up to the comment: This works for any emacs, either emacs or emacs-snapshot. For a long time I used (server-start) in the ~/.emacs but now I prefer that (just once) lauch emacs --daemon after which I can then connect to via emacsclient (which also exists as emacsclient-snapshot). I really like this -- it gives me Emacs around R in a persistent session that I connect, disconnect and reconnect to.

like image 93
Dirk Eddelbuettel Avatar answered Sep 22 '22 01:09

Dirk Eddelbuettel


I selected Dirk's answer because he pointed me in the right direction, and especially for lowering the energy of activation required to visualize my data, but here I am going to give the details of how I got this to work on my desktop.

1) set ssh keypairs (I had previously done this, full instructions for Ubuntu here)

mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa
ssh-copy-id username@hostname

2) include the following in ~/.ssh/config

Host any_server_nickname
HostName  hostname
User username
ForwardX11 yes

3) open emacs on local machine

4) C-x C-f

5) /any_server_nickname:dir/file.R for files in home directory or /any_server_nickname:/path/to/file.R

6) plot(1)

7) C-x C-b to evaluate entire buffer.

alt text

like image 36
David LeBauer Avatar answered Sep 18 '22 01:09

David LeBauer