15

I use Excel + R on Windows on a rather slow desktop. I have a full admin access to very fast Ubuntu-based server. I am wondering: how to remotely execute commands on the server?

What I can do is to save the needed variables with saveRDS, and load them on server with loadRDS, execute the commands on server, and then save the results and load them on Windows.

But it is all very interactive and manual, and can hardly be done on regular basis.

Is there any way to do the stuff directly from R, like

  1. Connect with the server via e.g. ssh,
  2. Transfer the needed objects (which can be specified manually)
  3. Execute given code on the server and wait for the result
  4. Get the result.

I could run the whole R remotely, but then it would spawn a network-related problems. Most R commands I do from within Excel are very fast and data-hungry. I just need to remotely execute some specific commands, not all of them.

Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68
  • You can call shell commands directly from R using `system`, so you could easily write the commands you're currently entering at the console into an R script. – Thomas Feb 27 '14 at 09:51
  • 4
    One of the options is to install Rstudio server and work from there. – Roman Luštrik Feb 27 '14 at 09:57
  • No. AFAIK RExcel doesn't work with remote connections, and even if it did, it wouldn't be efficient if I will start transferring all my data over network. I just need to remotely execute specific commands. – Adam Ryczkowski Feb 27 '14 at 10:51

3 Answers3

7

Here is my setup.

  1. Copy your code and data over using scp. (I used github, so I clone my code from github. This has the benefit of making sure that my work is reproducible)

  2. (optional) Use sshfs to mount the remote folder on your local machine. This allows you to edit the remote files using your local text editor instead of ssh command line.

  3. Put all things you want to run in an R script (on the remote server), then run it via ssh in R batch mode.

Heisenberg
  • 8,386
  • 12
  • 53
  • 102
4

There are a few options, the simplest is to exchange secure keys to avoid entering SSH/SCP passwords manually all the time. After this, you can write a simple R script that will:

  1. Save necessary variables into a data file,
  2. Use scp to upload the data file to ubuntu server
  3. Use ssh to run remote script that will process the data (which you have just uploaded) and store the result in another data file
  4. Again, use scp command to transfer the results back to your workstation.

You can use R's system command to run scp and ssh with necessary options.

Another option is to set up cluster worker at the remote machine, then you can export the data using clusterExport and evaluate expressions using clusterEvalQ and clusterApply.

df239
  • 471
  • 2
  • 4
3

There are a few more options: 1) You can do the stuff directly from R by using Rserve. See: https://rforge.net/

Keep in mind that Rserve can accept connections from R clients, see for example how to connect to Rserve with an R client.

2) You can set up cluster on your linux machine and then use these cluster facilities from your windows client. The simplest is to use Snow, https://cran.r-project.org/package=snow, also see foreach and many other cluster libraries.

Community
  • 1
  • 1
df239
  • 471
  • 2
  • 4