in reply to RSperl & threads

I was just meditating last night, and thought about your problem. I had a thought( better duck :-) ). If the RSPerl is an interpreter, which you send commands to stdin and get results out of stdout, you probably should run it thru IPC::Open3. I have sample code below
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; $|=1; #my $pid=open3(\*IN,\*OUT,\*ERR,'/bin/bash'); my $pid=open3(\*IN,\*OUT,0,'/bin/bash'); # set \*ERR to 0 to send STDERR to STDOUT my $cmd = 'date'; #my $cmd = 'top'; #send cmd to bash print IN "$cmd\n"; #getresult my $result = <OUT>; print $result;
Now you should be able to do a similar thing with the RSPerl interpreter. Of course, in a real script, you may want to separate stdout and stderr, and use IO::Select. Search for examples of IPC::Open3 for more detailed usage.

Now, once you get IPC::Open3 to run the interpreter, you can put the code into a thread, and pass in strings to be eval'd thru ther shared variable mechanism.


I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: RSperl & threads
by sperlyjinx (Initiate) on Apr 14, 2008 at 04:09 UTC
    Thanks to everyone for your input. I've solved the problem a slightly different way. I was able to set up a socket connection between R & Perl. If anyone is interested in the Perl or R code that accomplishes this, please let me know.
      Hi, could you please share the code with us all? I am a biologist used to working in R environment for my statistical analysis. But, now I have to call my .R files from perl. I have tried using RSperl, but it doesn't seem to support source("filename.R") function. Any take on this? Your comments are highly appreciated.
        Was this code ever posted anywhere?
      Yes, I am interested in the Perl and the R code. Thank you very much.
      i would be very interested in this code. can you post it up on here or send it to me directly?