I have the follow Java code that uses Rcaller.
RCaller caller = new RCaller();
RCode code = new RCode();
caller.setRscriptExecutable("/usr/bin/Rscript");
code.addRCode("install.packages(\"bbmle\")");
caller.redirectROutputToConsole();
caller.runOnly();
Essentially, I'm trying to run Java code that installs an R package (because later I will run R code within Java that requires this package).
When I run this code, I get the following output in Java
Error:Loading required package: Runiversal
However, I do have the Runiversal
package on my Mac. Any ideas what this means, and why I'm not actually seeing any R
output of the install.packages
method, which is normally quite verbose?
UPDATE: I should note that even simple code such as the following results in the same error:
code.addRCode("x = c(1,2,3)");
code.addRCode("y = c(2,3,5");
code.addRCode("x+y");
caller.redirectROutputToConsole();
caller.runOnly();
UPDATE: I should also mention that the following works great:
StringBuffer allCode = readFile("temp.R");
code.setCode(allCode);
double[] xvector = new double[]{1,3,5,3,2,4,5,6,7,8,9,21,22,25,27,25,34,39,31};
double[] yvector = new double[]{6,7,5,6,5,6,6,7,6,8,9,21,20,19,23,24,29,38,30};
code.addDoubleArray("X",xvector);
code.addDoubleArray("Y",yvector);
code.addRCode("fun(X,Y)");
temp.R:
fun = function(x,y) {
return(lm(y~x))
}
Java output:
Output:
Output:Call:
Output:lm(formula = y ~ x)
Output:
Output:Coefficients:
Output:(Intercept) x
Output: 2.445 0.825
Output:
R loads package from the libraries. If the library that you installed the Runiversal package into is not being searched by the R process started under Java, that could result in the error message you're seeing.
So: what is the directory path (i.e., library) that the Runiversal package is installed in? Possibly related to this is what user installed the R package, and what user is running the Java code.