I am running Java on Linux (CentOS), via the command line.
When I put the R command is a separate file, described in Section 1.4 of these docs,
I get the error:
Exception in thread "main" org.renjin.eval.EvalException: could not
find function 'engine.eval'
at org.renjin.eval.Context.evaluateFunction(Context.java:269)
at org.renjin.eval.Context.evaluateCall(Context.java:260)
at org.renjin.eval.Context.evaluate(Context.java:193)
at org.renjin.eval.Context.evaluateExpressionVector(Context.java:252)
at org.renjin.eval.Context.evaluate(Context.java:191)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:131)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:127)
at org.renjin.script.RenjinScriptEngine.eval(RenjinScriptEngine.java:107)
at pkg3.Temp3.main(Temp3.java:31)
I have the CLASSPATH
set correctly, because:
cd ~/rjtest
javac pkg3/Temp3.java
cd ~/rjtest
java pkg3.Temp3
produces:
x y
1 1 1.121
2 2 0.525
3 3 1.811
4 4 1.914
5 5 5.389
6 6 8.501
7 7 6.477
8 8 7.805
9 9 8.625
10 10 10.033
Call:
lm(formula = y ~ x, data = df)
Coefficients:
(Intercept) x
-0.902 1.113
Modifing the code to move the 3 engine.eval
statements into script.R
:
// engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))");
// engine.eval("print(df)");
// engine.eval("print(lm(y ~ x, df))");
engine.eval(new java.io.FileReader("/pathto/rjtest/pkg3/script.R"));
javac compiles with no error, but java gives the error.
The code engine.eval()
is a Java statement. The Exception you're getting is Renjin telling you that there is no R function called engine.eval
. Your script.R should contain:
df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))
print(df)
print(lm(y ~ x, df))"
Not:
engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))")
engine.eval("print(df)");
engine.eval("print(lm(y ~ x, df))")
Which is, coincidentally, valid R syntax, but not what you want.