Question

UPDATE: SOLVED I've discovered the issue.

Using the .libPaths() function, I was able to determine that the default directory that the HH package installed into was not included in the library paths when running Rscript through PHP, even though it was appearing when R was executing the same code through the command prompt.

I've resolved the issue by include a separate call to .libPaths('new/file/path'); in my dynamically created syntax. When I do this, test <-require('HH'); test; returns TRUE;

Thanks to all who helped.

I'm in the process of creating a PHP script that will run some analyses in R. This analysis requires the hov.bf() function, which is a part of the HH package, but all R output (and presumably processes associated with R) stops from the line where the hov.bf() function is called. The same symptom occurs if I try loading the HH library via library('HH');. What's confusing me, the exact same R syntax code executes and outputs ALL print statements(base and HH functions) without error when run via the (Ubuntu) command prompt.

Overview of code:

PHP creates R syntax and writes to file Rsyntax.txt. Some of the following lines are located in the R syntax file:

dir = '/var/www/someDirectory/';
setwd(dir);
sink('record.lis', append=FALSE, split=TRUE);

print('hello-1');
test <- hov.bf(Values,Grouping);
print('hello-2');

q();

After syntax file is generated, PHP then runs:

exec("/usr/bin/Rscript /var/www/someDirectory/Rsyntax.txt --no-save", $output);

When run through PHP, the output file will contain all output created above the call to hov.bf(), but nothing seems to run after this call. That is, "hello-1" is present in the output file, but "hello-2" and all other output below the hov.bf() call is not written to the file. However, when I copy and paste the exact command from PHP's exec() to Ubuntu's command prompt, it runs all R syntax without issue. I have also tried setting the .Rprofile to load the HH package as a default when R is loaded, but this did not resolve the issue through PHP.

If anyone has any ideas, I would greatly appreciate them. I've run out of ideas for what it might be.

Thank you.

Was it helpful?

Solution

I've discovered the issue.

Using the .libPaths() function, I was able to determine that the default directory that the HH package installed into was not included in the library paths when running Rscript through PHP, even though it was appearing when R was executing the same code through the command prompt.

I've resolved the issue by include a separate call to .libPaths('new/file/path'); in my dynamically created syntax. When I do this,

test <-require('HH'); 
test; 
returns TRUE;

Thanks to all who helped.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top