The main setup of the project I'm working on (Windows) is the Electron application, which communicates with R through R. Now everything works fine, except for one thing that has been driving me crazy lately.
The problem is that when I use the node from cmd (etc. node startR.js etc.) and execute the R script with the following command:
var exec = require('child_process').exec;
var executableR = exec('Rscript startR.R', function(error, stdout, stderr) {
console.log(stdout);
});
and R-type code:
library('Rserve')
Rserve()
everything is going well. But when I try to execute the same line in the main.js (entrypoint) file for my Electron application, I get an error that R libraries (i.e. Rserve) cannot be found from R.
I checked the possible reasons for this, and I found that the paths of the R library are different (.libPaths ()) when R is called from the cmd node and from the electron. Namely, R libs are installed in the MyDocuments folder, and R, called from the cmd node, seems to see them correctly. On the other hand, the same exec from the electron does R, which sees only the default library path (in program files where R is installed), so it does not find the library.
I know that this should be a problem with the environment (for example, starting it from an environment other than the current user), but I'm not sure what to try. I thought passing process.env to the {env:} option for child_process.exec, but to no avail.
source
share