KingOfBabu
KingOfBabu

Reputation: 409

shell_exec doesn't work properly on windows

When I write this script on the command prompt, it works properly :

R CMD BATCH test.R

But, when I'm trying to execute this code in php on windows with :

shell_exec(R CMD BATCH test.R)

It gives me a error : "Error in library(raster) : packages 'raster' was not found"
This has no sense because it does work on unix !

Upvotes: 1

Views: 1764

Answers (1)

Clay
Clay

Reputation: 4760

A couple possiblities:

  1. raster package is not installed

  2. PHP PATH when calling shell_exec has different environment variables set so it is not loading the right libs (try setting R_LIBS to fix it).

  3. Try using an absolute path to r instead of a relative one.

for R_LIBS mentioned above: https://stat.ethz.ch/R-manual/R-devel/library/base/html/libPaths.html

By default R_LIBS is unset, and R_LIBS_USER is set to directory ‘R/R.version$platform-library/x.y’ of the home directory (or ‘Library/R/x.y/library’ for CRAN OS X builds), for R x.y.z.

Example from their FAQ:

"path_to_R\bin\x64\Rgui.exe" HOME=p:/ R_LIBS=p:/myRlib

Upvotes: 2

Related Questions