pacomet
pacomet

Reputation: 5141

Running R script from php webpage

I am trying to build a php file that allows users to run a R script so they don't need to open a session in the server, just to open a browser.

Usual bash from the script run fine (say echo "something", copy and move data files,...) but R script is not running. R is called with Rscript

Rscript --no-save --no-restore --verbose ./RAMS-mapa-onades-zones-manual.R > outputFile.Rout 2>&1

R output gives this error

running
  '/usr/lib/R/bin/R --slave --no-restore --no-save --no-restore'

Error in library("rgdal") : there is no package called 'rgdal'
Execution halted

Well, library(rgdal) is the first line of the R script. Rgdal is present on the R installation and the script runs fine (Rscript myscript.R) from the command line.

As starting from php, the user running R is www-data while on the terminal the user is meteo. It seems to me that some environment variable needs to be set in the php Rscript execution but I can't find the way to do it.

Any idea? Thanks in advance

Upvotes: 3

Views: 1247

Answers (1)

LauriK
LauriK

Reputation: 1929

Seems we've found the root cause in comments. The library paths don't match, but you can make them match by the lib.loc parameter to library(). Like this:

library(rgdal, lib.loc = c("/home/meteo/R/i686-pc-linux-gnu-library/3.1", "/usr/local/lib/R/site-library", "/usr/lib/R/library"))

Upvotes: 2

Related Questions