-
Notifications
You must be signed in to change notification settings - Fork 0
/
ess-via-tramp.Rmd
77 lines (52 loc) · 2.66 KB
/
ess-via-tramp.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
categories:
- tutorials
date: "2021-01-06"
tags:
- emacs
- programming
- bioinformatics
- R
- remote
title: "Getting Started with R Programming in Emacs: working on a remote server"
slug: emacs-tutorial-remote
author: "Chris Wallace"
---
It can be slow and frustrating to run R via a GUI when your data and R are on a remote server. Emacs has long had support for editing remote files via [tramp](https://www.gnu.org/software/tramp/), and ESS allows emacs to interact with a remote R process. This can bring the best of both worlds: a GUI editor running locally (so fast), interacting with an R process on the remote server. Graphics can be served from the remote server as long as you have lines like
```
Host *
ForwardX11 yes
```
in your ssh config file (`~/.ssh/config` on a linux machine).
In this doc, I assume
- emacs is installed on the local machine `A`
- R is installed on the remote server `B`
- you know how to ssh from `A` to `B`
- you have installed ESS as described in [intro to ESS](https://github.com/ess-intro/presentation-ess-base-install)
Your R script files can be on either `A` or `B`.
# Starting a remote R process within emacs
First open a file or directory on the remote server over ssh.
`C-x C-f /ssh:user@B:~/ RET`
If you have aliases set up in your `$HOME/.ssh/config` you can use the alias here instead of `user@B`. Then if you start an R process from that buffer, it will call R on the machine `B`. Do this by
`M-x R`
That's it, you have a running R process on the remote machine. Type
`system("hostname")`
to check.
# Interacting with a remote R process from an R script on a remote server
Open the remote R script over ssh. E.g. if the script is called myscript.R in your remote home directory, do
`C-x C-f /ssh:user@B:~/myscript.R RET`
Start an R process from that buffer, it will split the window if needed, and start on the machine `B`. Do this by
`M-x R`
That's it, you should have a running R process on the remote machine. All the standard ESS commands should work. So if you type a line in the script file, you can run it in the R process using
`C-c RET`
or run a block of code using
`C-c C-c`
See the [intro to ESS](https://github.com/ess-intro/presentation-ess-base-install) to learn more.
# Configuring tramp
While tramp comes with emacs, there are a couple of settings that can help if you add them to your emacs config file
```
;; ssh seems the most reliable connection method
(setq tramp-default-method "ssh")
;; this sets the path on the remote server according to the ~/.profile file on the remote machine. Useful if your R is in a non-standard location
(add-to-list 'tramp-remote-path 'tramp-own-remote-path))
```