R script is not loading (kohonen library) and it is not executing in php code and same code is executing in terminal

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");

R code

load(file = "som.rda")

write.table(compile11, file = "kohonen1.txt")
and etc........

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



it is not printing c in output file, because of kohonen library

same addition i tried with loading nnet library



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

Hi @sathyaseelan! Welcome!

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:

out <- file("messages.Rout", open = "wt")
sink(out, type = "message")
sink() # just in case loading the library works for some reason!
1 Like

Dear jcblum

Thank you so much for your sugesstion

I followed the commands as you provided

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

Please suggest me to solve this error

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! :sweat_smile:

1 Like

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.

Thank you once again....