2

Is there a way to pass commands (from a shell) to an already running R-runtime/R-GUI, without copy and past.

So far I only know how to call R via shell with the -f or -e options, but in both cases a new R-Runtime will process the R-Script or R-Command I passed to it.

I rather would like to have an open R-Runtime waiting for commands passed to it via whatever connection is possible.

zx8754
  • 52,746
  • 12
  • 114
  • 209
user320602
  • 71
  • 1
  • 1
  • 2
  • 1
    It would be helpful to know what operating system you are using as the details of some possible solutions to your problem can be highly OS specific. Additionally, it would be nice to have some context- what are you doing that requires passing calls to R? Different techniques may be appropriate depending on what you are trying to achieve. – Sharpie Apr 22 '10 at 17:41
  • I want to use one R-Runtime at two different occasions. Passing single commands or whole R-Scripts. Right now I work with Windows7-64bit, but the Solution I am looking for should work with Suse-Linux as well. – user320602 Apr 23 '10 at 16:37

3 Answers3

7

What you ask for cannot be done. R is single threaded and has a single REPL aka Read-eval-print loop which is, say, attached to a single input as e.g. the console in the GUI, or stdin if you pipe into R. But never two.

Unless you use something else as e.g. the most excellent Rserve which (when hosted on an OS other than Windoze) can handle multiple concurrent requests over tcp/ip. You may however have to write your custom connection. Examples for Java, C++ and R exist in the Rserve documentation.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • I didn't want to have two seperat connection to one R-Runtime. I was looking to use one connection at two seperat occasion. But Rserve looks quite like what I was looking for. But I'll have too look more closer into it. – user320602 Apr 23 '10 at 16:26
0

You can use Rterm (under C:\Program Files\R\R-2.10.1\bin in Windows and R version 2.10.1). Or you can start R from the shell typing "R" (if the shell does not recognize the command you need to modify your path).

teucer
  • 6,060
  • 2
  • 26
  • 36
  • 1
    Sorry, but I think you missunderstood my question. I know I can call R-Runtime from shell, but thats not the point. The point is I want to call "R -e 'a <- 3'" and next time "R -e 'print(a)'". Like this it will now work since both commands will have thier own R-Runtime so that the second command will through an Error "object 'a' not found" – user320602 Apr 22 '10 at 11:54
0

You could try simply saving the workspace from one session and manually loading it into the other one (or any kind of variation on this theme, like saving only the objects you share between the 2 sessions with saveRDS or similar). That would require some extra load and save commands but you could automatise this further by adding some lines in your .RProfile file that is executed at the beginning of every R session. Here is some more detailed information about R on startup. But I guess it all highly depends on what are you doing inside the R sessions. hth

davidski
  • 561
  • 1
  • 4
  • 16