5

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.

David LeBauer
  • 31,011
  • 31
  • 115
  • 189
  • Not an answer, but it isn't working because the ssh command doesn't include the `-X` option to turn on X forwarding over the connection. – Gavin Simpson Nov 11 '10 at 08:14
  • that is the answer. I just didn't think of it because I set up an alias for 'ssh server' so I just have to type 'server' so I'll just have to set up a new alias that includes the -x. thanks! – David LeBauer Nov 11 '10 at 13:10
  • 2
    Alternatively, you can hardcode X11 forwarding in the system-wide `/etc/ssh/ssh_config` or your local `~/.ssh/config` -- see `man ssh_config`. Also, just to be pedantic, my answer included `ssh -X` . – Dirk Eddelbuettel Nov 11 '10 at 13:40
  • thanks for pointing that out. I didn't accept your original answer because it required -nw terminal mode. I'd accept your answer if you add this part since it does what I want. – David LeBauer Nov 11 '10 at 14:05
  • No it doesn't require '-nw' at all. I simply do that because I also use `screen` / `byobu`. Your emacs can be started in text or graphics. The key really is a) you want emacs as a server and b) you want ssh with x11 forwarding. – Dirk Eddelbuettel Nov 11 '10 at 15:54

2 Answers2

13

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks for the suggestion. How do you start and stop emacs without ending your R session? I use emacs -nw some, but I find it much easier to work in and configure emacs-snapshot. – David LeBauer Nov 11 '10 at 03:11
  • 5
    @David, if you start emacs on the server using the daemon option, R keeps running when you close the emacs client. This is because emacs (and thus R) are running like services. After Dirk explained this to me. I've been doing this very thing to connect to ESS running on EC2. I've stopped carrying my laptop home now that I can just connect another emacs client to the same session from my home machine. – JD Long Nov 11 '10 at 14:18
  • This looks very interesting and useful. I will look in to this - thanks for re-emphasizing Dirk's suggestion. – David LeBauer Nov 11 '10 at 15:50
  • Dirk, this is fantastic news to me. Thank you! – Andreas Nov 24 '18 at 06:18
3

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

David LeBauer
  • 31,011
  • 31
  • 115
  • 189
  • In step 4 are you opening emacs locally or on the remote server? – JD Long Nov 11 '10 at 15:53
  • I had not come across `ssh.el` -- what does `ssh.el` do that standard `tramp-mode` (which is included with Emacs) doesn't do? – Dirk Eddelbuettel Nov 11 '10 at 15:55
  • @JD Long: step 4 I am opening emacs locally – David LeBauer Nov 11 '10 at 16:18
  • @Dirk I learned about the ssh.el mode from section 3.3 of the ess manual [1] (ESS processes on Remote Computers) 'the recommended way to access a statistical program on a remote computer' if I had read the whole section, I would have read that using X11 I should seting the DISPLAY environment variable... but setting the ssh_config file works too. They don't mention the use of C-x C-f /server:... in the manual, so now I am not sure if this is dependent on ssh.el or not. [1] http://ess.r-project.org/Manual/ess.html#ESS-processes-on-Remote-Computers – David LeBauer Nov 11 '10 at 16:25
  • @Dirk ... I don't know all of the differences between tramp mode and ssh.el; looking at the output in my original question, it appears that ess is using tramp mode. What ssh.el does allow is the command M-x ssh servername 'terminal appears' R M-x ess-remote. This is the recommended way to start an interactive R session in the ess manual although I usually don't use this approach since it takes so many more steps and I usually use the non-emacs terminal on my local machine for interactive mode since emacs doesn't behave the same in terminal mode as the terminal does – David LeBauer Nov 11 '10 at 16:33
  • Google up on tramp mode -- you may like that. I suspect (and only talking to ESS devs can help here) that the paragraph on the manual predates tramp and/or the inclusion of tramp mode in recent Emacsen. – Dirk Eddelbuettel Nov 11 '10 at 16:34
  • @Dirk ... I don't know all of the differences between tramp mode and ssh.el; looking at the output in my original question, it appears that ess is using tramp mode. What ssh.el does allow is the command M-x ssh servername 'terminal appears' R M-x ess-remote. This is the recommended way to start an interactive R session in the ess manual although I usually don't use this approach since it takes so many more steps and I usually use the non-emacs terminal on my local machine for interactive mode since emacs doesn't behave the same in terminal mode as the terminal does – David LeBauer Nov 11 '10 at 16:35
  • so it appears I have been using the tramp mode without realizing that this is what has simplified my life. – David LeBauer Nov 11 '10 at 16:44