Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Rscript' is not recognized as an internal or external command, operable program or batch file

Tags:

shell

path

php

r

cmd

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.

like image 801
Hemant Pandey Avatar asked Dec 02 '22 15:12

Hemant Pandey


2 Answers

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.

like image 193
Tunn Avatar answered Dec 06 '22 09:12

Tunn


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 
like image 22
user5249203 Avatar answered Dec 06 '22 09:12

user5249203