I need to call R from within a Perl script. I do so using a system call like this: @args = ('R --vanilla --quiet --file=Rblock'); system(@args) == 0 or die "system @args failed: $!"; The script works perfectly when run in Mac OSX or Linux. In Windows XP it fails with the message " 'R' is not recognized as an internal or external command, operable program or batch file". To ensure that R was properly installed and that the environment variable "path" was correctly set, I executed the same command (R --vanilla --quiet --file=Rblock) from the command line and it worked perfectly; i.e. R ran with the expected behavior. Similar system calls to other external programs, e.g. @args = ('Notepad'); system(@args) == 0 or die "system @args failed: $!"; work perfectly. Is there any obvious reason that this particular call works from the command line but not from within a perl script? Thanks for any assistance -- View this message in context: http://r.789695.n4.nabble.com/Problem-calling-R-from-within-perl-script-on-Windows-tp2260646p2260646.html Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2010-Jun-18 21:03 UTC
[R] Problem calling R from within perl script on Windows
On Fri, Jun 18, 2010 at 3:11 PM, Barry Hall <barryhall at zeninternet.com> wrote:> > I need to call R from within a Perl script. ?I do so using a system call like > this: > @args = ('R --vanilla --quiet --file=Rblock'); > system(@args) == 0 or die "system @args failed: $!"; > > The script works perfectly when run in Mac OSX or Linux. ?In Windows XP it > fails with the message " 'R' is not recognized as an internal or external > command, operable program or batch file". > > To ensure that R was properly installed and that the environment variable > "path" was correctly set, I executed the same command (R --vanilla --quiet > --file=Rblock) from the command line and it worked perfectly; i.e. R ran > with the expected behavior. > > Similar system calls to other external programs, e.g. > @args = ('Notepad'); > system(@args) == 0 or die "system @args failed: $!"; > work perfectly. > > Is there any obvious reason that this particular call works from the command > line but not from within a perl script? >That error is coming from the Windows console so you likely have a PATH problem. Fix your path or use the absolute path in your program. Note that unless you told it not to under normal circumstances the R installer puts a key in the registry and you can alternatively look it up to find R that way. A batch file that does that is in the batchfiles collection at http://batchfiles.googlecode.com
Erik Iverson
2010-Jun-18 21:04 UTC
[R] Problem calling R from within perl script on Windows
Someone with more Windows and/or Perl experience will be of more use, but guessing here: 1) Try calling system with a program that echoes the path, perhaps the system command is not using the same path variable as you think. 2) specify the full path to R (using proper escaping of backslashes and/or spaces as necessary), and see if that helps at all. Barry Hall wrote:> I need to call R from within a Perl script. I do so using a system call like > this: > @args = ('R --vanilla --quiet --file=Rblock'); > system(@args) == 0 or die "system @args failed: $!"; > > The script works perfectly when run in Mac OSX or Linux. In Windows XP it > fails with the message " 'R' is not recognized as an internal or external > command, operable program or batch file". > > To ensure that R was properly installed and that the environment variable > "path" was correctly set, I executed the same command (R --vanilla --quiet > --file=Rblock) from the command line and it worked perfectly; i.e. R ran > with the expected behavior. > > Similar system calls to other external programs, e.g. > @args = ('Notepad'); > system(@args) == 0 or die "system @args failed: $!"; > work perfectly. > > Is there any obvious reason that this particular call works from the command > line but not from within a perl script? > > Thanks for any assistance
Berend Hasselman
2010-Jun-19 08:36 UTC
[R] Problem calling R from within perl script on Windows
Barry Hall wrote:> > I need to call R from within a Perl script. I do so using a system call > like this: > @args = ('R --vanilla --quiet --file=Rblock'); > system(@args) == 0 or die "system @args failed: $!"; >Try this @args = ('R', '--vanilla --quiet --file=Rblock'); i.e. make @args consist of two items: the first is the command/program you want to run and the second consists of the command line arguments you want to pass to the program. /Berend -- View this message in context: http://r.789695.n4.nabble.com/Problem-calling-R-from-within-perl-script-on-Windows-tp2260646p2261032.html Sent from the R help mailing list archive at Nabble.com.