I am running R script in the php code in apache webserver, in my script I am giving code for loading ( kohonen library). whole R-script will be running through php coding as exec("Rscript script.R");
in terminal this code is running, but while giving in php it is not executing and loading the library
for checking the library loading, i wrote simple code for addition by loading library in first line
example
library("kohonen")
a<-3
b<-5
c<-a+b
print(c)
it is not printing c in output file, because of kohonen library
same addition i tried with loading nnet library
example
library("nnet")
a<-3
b<-5
c<-a+b
print(c)
It is printing c in the output file. problem is with loading kohonen library please suggest me, how to load kohonen libary and then how to fix this problem
To understand why kohonen isn’t loading, you’ll probably need to take a look at whatever errors and warnings are emitted when you try to load it.
What happens if you try using sink() (or capture.output()) in a test script to write those messages to a file?
For example:
setwd("path/where/you/want/output")
out <- file("messages.Rout", open = "wt")
sink(out, type = "message")
library("kohonen")
sink() # just in case loading the library works for some reason!
I am getting the following lines in message.Rout file
> Error: package or namespace load failed for 'kohonen' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
> there is no package called 'Rcpp'
> Execution halted
It looks like the package Rcpp (one of kohonen’s dependencies) is not installed from the point of view of the R installation that’s being invoked when your script runs on your server.
I’m guessing that the R installation you are accessing when you run your script at the terminal (I’m not sure if you mean a terminal session on the server, or something else) has all the necessary dependencies installed, which is why the script runs fine in that context.
So I think you need to take a look at your system setup to understand what the configuration problem is here. Does your PHP code wind up invoking a different R installation than you expect? Or are there environment variables (e.g. influencing .libPaths()) that are set in such a way that the R run that way can’t find all its libraries (= places packages are installed)? There are probably several other ways this could be going wrong that I’m not thinking of!
Dear Jcblum
Thank you so much for your sugesstion. I checked libPaths() command, it showed three different paths where R packages were installed, in some paths R packages were not installed. so i installed all required packages in all three paths, then it worked for me.