'Rscript' is not recognized as an internal or external command, operable program or batch file
Solution 1
Add the Rscript
path to your environment variables in Windows:
Go to Control Panel\System and Security\System and click Advanced System Settings, then environment variables, click on path in the lower box, edit, add "C:\R\R-3.2.2\bin"
Restart everything. Should be good to go. Then you should be able to do
exec('Rscript PATH/TO/my_code.R')
instead of typing the full path to Rscript
. Won't need the path to your my_code.R script if your php file is in the same directory.
Solution 2
You need to set the proper path where your RScript.exe program is located.
exec ("\"C:\\R\\R-3.2.2\\bin\\Rscript.exe\"
C:\\My_work\\R_scripts\\my_code.R my_args";
#my_args only needed if you script take `args`as input to run
other way is you declare header in your r script (my_code.r)
#!/usr/bin/Rscript
and call it from command line
./my_code.r
Hemant Pandey
Updated on November 18, 2021Comments
-
Hemant Pandey over 2 years
shell_exec("Rscript C:\R\R-3.2.2\bin\code.R ");
This is the call to script.On calling the above script, the error occurs.
I am trying to call my R script from the above path but no output is being shown. While checking the error logs of PHP, it says 'Rscript' is not recognized as an internal or external command, operable program or batch file.' The script is working fine on the Rstudio but not running on the command line.
-
georoot about 8 yearsPlease be more descriptive and also attach the error that you are getting
-
Oliver Frost about 8 yearsYou could try something like this in the command prompt:
cd C:\R\R-3.2.2\bin\ & Rscript "C:\R\R-3.2.2\bin\code.R"
, or possibly:cd C:\R\R-3.2.2\bin\ & Rscript code.R
. Basically, usecd
to change directory to the location of your Rscript.exe, then run a second command using&
with the Rscript and the path to your script. -
Dave2e about 8 yearsAnother option is include the path as part of the Rscript command: "C:\R\R-3.2.2\bin\Rscript" C:\R\R-3.2.2\bin\code.R
-
Hemant Pandey about 8 years@Dave2e Thanks....that solved the problem :D
-