Friday, April 24, 2015

How to set R environment variables on Linux


I call an R script from PHP and it works well. 
I just call it using this function


shell_exec("Rscript play.r");

To do that I had to set environment variables in Windows
to the R executable be recognized by the OS.


Well now I am trying to do the same for Linux. I have the same error that I had on Windows before setting environment variables:


Rscript:not found 127

I think the Linux operating system is not finding the path to the R "executable" when I call it from PHP.


I think that I must to set the environment variables to R on Linux
but I don't know how to do that.


What should I do?


Answer



You do not necessarily need to set environmental variables. Simply call Rscript by its full path:


shell_exec("/usr/local/bin/Rscript ...");

Of course, change the path to wherever it really is. You can check from a shell by running which Rscript.


If you really want to change the PATH for PHP, you should check this Stack Overflow post.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...