Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi all

I want to be able to call R to do some stats from perl. I can do this fine with backticks giving R an input file as a parameter, but what I really want to be able to do is start R running and send it commands from my perl script and get its output back as I go along. Googling suggests this is not as simple as it sounds and I'm getting a little lost reading pages of stuff about fork, pipe, exec, open2, etc. Am I looking in the right place? Can anyone point me to an example that does something similar?

Many thanks, Cxx

Replies are listed 'Best First'.
Re: running R from perl
by Albannach (Monsignor) on Mar 26, 2004 at 18:08 UTC
    Did you look in CPAN? It appears that Statistics::R may be relevant, and will hide a lot of the gory details as well.

    --
    I'd like to be able to assign to an luser

      Am a muppet - didn't even occur to me that someone might have done this already. Will go have a play with it and let you know how it goes.

      Thanks for your help. Cxx

        Am a muppet
        Wocka wocka wocka, I too neglected to search for available tools, but what they hey, I didn't even know what 'R' was. Check out Expect in your spare time after you get your 'R' work done, it's still cool.
Re: running R from perl
by flyingmoose (Priest) on Mar 26, 2004 at 18:06 UTC

    Expect performs such black magic. If you are running on Unix/Linux, this is exactly what you want. If you open the Expect.pm POD (via my link), and search for "How to automate login" you will see a top-to-bottom example of Expect looking for patterns and responding to them using anonymous subroutine handlers. Very cool.