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

Hello Perl Monks

Statistics::R questions

this works:

$R->send(q`a<-read.table("/usr/local/projects/file")`);

this doesnt work:

$file="/usr/local/projects/file"; $R->send(q`a<-read.table($file)`);

Does anybody know how I get the above working?

Many Thanks Perl Monks

Replies are listed 'Best First'.
Re: Statistics::R question
by Corion (Patriarch) on Apr 06, 2011 at 11:04 UTC

    Use

    my $command = q`a<-read.table("/usr/local/projects/file")`; print "Running [$command]\n"; $R->send($command);

    and

    my $file="/usr/local/projects/file"; my $command = q`a<-read.table($file)`; print "Running [$command]\n"; $R->send($command);

    to see what happens and what the first cause is. Then look at perlop, especially at the "Quotes and Quote-like operators" to see what causes this behaviour of Perl and what to change.

      Thanks corion for your pointer to help.
      
      
      This now works, not sure if its the proper way.
      
      my $file="/usr/local/projects/file";
      my $command = "a<-read.table(\"$file\")";
      print "Running $command\n";
      $R->send($command);
      
      
      Thanks again!
      
Re: Statistics::R question
by wind (Priest) on Apr 07, 2011 at 01:08 UTC

    q doesn't interpolate. You wanted qq instead or "..." like you used in the end.

    Also, I would shy away from using backticks as your separator as that can be confused with qx.

    my $file = '/usr/local/projects/file'; $R->send(qq{a<-read.table("$file")});
      Thanks for your help wind, very useful, I will be using that from now onwards