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

元气小坏坏 提交于 2019-12-20 16:41:33

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4150078/how-can-i-launch-an-x-window-from-emacs-ess-when-running-r-on-a-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!