[R] question about using a remote system

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu May 28 08:33:13 CEST 2009


On 28-May-09 00:58:17, Erin Hodgess wrote:
> Dear R People:
> I would like to set up a plug-in for Rcmdr to do the following:
> 
> I would start on a Linux laptop.  Then I would log into another
> outside system and run a some commands.
> 
> Now, when I tried to do
> system("ssh erin at xxx.edu")
> password xxxxxx
> 
> It goes to the remote system.  how do I continue to issue commands
> from the Linux laptop please?
> 
> (hope this makes sense)
> thanks,
> Erin

Hi Erin,
If I understand what you want, I think you may be asking a bit
too much from R itself.

When you, Erin, are interacting with your Linux laptop you can
switch between two (or more) different X windows or consoles,
on one of which you are logged in to the remote machine and on
which you issue commands to the remote machine, and can read
its output and, maybe, copy this to a terminal running commands
on your Linux laptop.

When you ask R to log in as you describe, you are tying that
instance of R to the login. I don't know of any resources within
R itself which can emulate your personal behaviour. Though maybe
others do know ...

However, there is in principle a work-round. You will need to
get your toolbox out and get to grips with "Unix plmubing";
and, to make it accessible to R, you will need to create a
"Unix plumber".

The basic component is the FIFO, or "named pipe". To create
one of these, use a Linux command like

  mkfifo myFIFO1

Then 'ls -l' in the directory you are working in will show this
pipe as present with the name "myFIFO1". For example, if in one
terminal window [A] you start the command

  cat myFIFO1

then in another [B] you

  echo "Some text to test my FIFO" > myFIFO1

you will find that this text will be output in the [A] window
by the 'cat' command.

Similarly, you could 'mkfifo myFIFO2' and write tc this while
in the [A] window, and read from it while in the [B] window.

So, if you can get R to write to myFIFO1 (which is being read
from by another program which will send the output to a remote
machine which that program is logged into), and read from myFIFO2
which is being written to by that other program (and that is
easy to do in R, using connections), then you have the plumbing
set up.

But, to set it up, R needs to call in the plumber. In other words,
R needs to execute a command like

  system("MakeMyFIFOs")

where MakeMyFIFOs is a script that creates myFIFO1 and myFIFO2,
logs in to the remote machine, watches myFIFO1 and sends anything
it reads to the remote machine, watches for any feedback from
the remote machine and then writes this into myFIFO2.

Meanwhile, back in R, any time you want R to send something to
the remote machine you write() it (or similar) to myFIFO1, and
whenever you want to receive something from the remote machine
you readLines() it (or similar) from myFIFO2.

That's an outline of a possible work-round. Maybe other have solved
your same problem in a better way (and maybe there's an R package
which does just that ... ). If so, I hope they'll chip in!

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 28-May-09                                       Time: 07:33:09
------------------------------ XFMail ------------------------------




More information about the R-help mailing list