I took over an old project from an other person. Currently I'm trying to get this project to work.
Already in the beginning I get an Exception in:
R.parseAndEval(".jengine()");
It throws a REngineEvalExcpetion: error during evaluation.
If I use R in the R-Console, I needed to add a parameter .jengine(start=TRUE) to get the command .jengine() working. So I changed this line in Java accordingly, but I still get the same Exception.
I did a tutorial with R without calling .jengine() and using Rengine instead of REngine and at least somehow it worked and I could call R commands within Java.
I'm currently using R 3.3.3 and Java 1.8. I also don't know which versions have been used previously.
"error during evaluation" just means that the R thread that is running the R script failed to run that command. But everything in the Java application is working properly. Is R that is failing.
R has to have the rJava library in order to run .jengine:
library(rJava)
.jinit(".")
.jengine(TRUE)
Related
I have a spring boot application which is calling Rscript using Rcode and while running it on a Windows machine it is working properly, I'm trying to dockerize it.
In my docker container, I'm getting the below error.
java.util.concurrent.ExecutionException: com.github.rcaller.exception.ExecutionException: R command failed with error. Reason: Error: package or namespace load failed for ‘data.table’:
object 'as.xts' not found whilst loading namespace 'data.table'
In addition: Warning message:
package ‘data.table’ was built under R version 3.6.3
Execution halted
Tried multiple options like setting environmental variables, checking R compatibility issue.
I'm new to R, how to make sure all the required R packages are properly installed?
Not finding any workaround.
Your suggestions will be very much appreciated.
I am trying to code using the rSymPy package. When I type in library(rSymPy) I get the following warnings:
> library(rSymPy)
Loading required package: rJython
Loading required package: rJava
Loading required package: rjson
Warning messages:
1: package ‘rJava’ was built under R version 3.4.4
2: package ‘rjson’ was built under R version 3.4.4
This is fine because in theory my code should still work. However, when I try running my function which uses the sympy() command I get the following error:
> moment_generating_function(12)
Show Traceback
Error in .jcheck() : No running JVM detected. Maybe .jinit() would help.
I then run .jinit() which produces no output. Running my code again, I now get the following error
Error in .jcall("RJavaTools", "Z", "hasField", .jcast(x, "java/lang/Object"), :
java.lang.NullPointerException
I have tried reinstalling my JDK and tried running "r cmd javareconf;" in my terminal multiple times. I would just code this directly in Python but unfortunately my assignment requires I use the rSymPy package in R. I would greatly appreciate any help with this.
On the computers (running fedora) at my work R-2.15 is installed by default. I downloaded R-3.0.2 because I need several packages which are only available for R 3.
When i try to call an Rscript from java using Runtime.getRuntime().exec(command); with command being the String Array {"/path/to/Rscript/3-0" "name/of/script" "...args..."} I get the error WARNING: ignoring environment value of R_HOME and it says that it couldn't load the needed packages. When i run the very same command in a terminal it works well.
What is the difference between the call via java and the call on the console. And how can I fix it?
EDIT 1:
when i run my locally installed R-3 version, libPaths returns
> .libPaths()
[1] "/home/<homedir>/.bin/R-3.0.2/library"
But when i call an Rscript from Java, libPaths returns
[1] "/home/<homedir>/R/x86_64-redhat-linux-gnu-library/2.15"
[2] "/usr/lib64/R/library"
[3] "/usr/share/R/library"
[4] "/home/<homedir>/.bin/R-3.0.2/library"
The problem seems to be that Java adds any environment variables that tell R to load packages from the 2.15 installation. How can i prevent this?
EDIT 2:
When i list all environment variables using the System.getenv(); method nothing R-related is shown, the same is the case when i list the environment variables using printenv in the terminal. But when i call Sys.getenv in R the variables R_HOME, R_LIBS, ... are defined. How are these defined?
You can choose the library to look in when you load the package. For example, when calling the script via Rscript, you could use
library(rJava, lib.loc = .libPaths()[4])
I'm trying to call a java program from python using command line. The code is as follows:
subprocess.check_output(["java", "pitt.search.semanticvectors.CompareTerms", "-queryvectorfile","termvectors.bin","term1","term2"])
I get the following error:
Error: Could not find or load main class pitt.search.semanticvectors.CompareTerms
This happens when I run the program from PyDev (version 2.5 in Eclipse 3.7.2). However, if I run the same code from the terminal, it works and I get the result I want.
I'm almost sure that the problem is related with some configuration of PyDev and how it handles the java CLASSPATH, which is:
/Users/feralvam/Programas/semanticvectors-3.4/semanticvectors-3.4.jar:/Users/feralvam/Programas/lucene-3.5.0/lucene-core-3.5.0.jar:/Users/feralvam/Programas/lucene-3.5.0/contrib/demo/lucene-demo-3.5.0.jar:
The class "pitt.search.semanticvectors.CompareTerms" is in "semanticvectors-3.4.jar".
Any help you could give me would be really appreciated.
Thanks!
The solution proposed by #eis worked. Now, the command is:
subprocess.check_output(["java", "-classpath", "/Users/feralvam/Programas/semanticvectors-3.4/semanticvectors-3.4.jar:/Users/feralvam/Programas/lucene-3.5.0/lucene-core-3.5.0.jar:/Users/feralvam/Programas/lucene-3.5.0/contrib/demo/lucene-demo-3.5.0.jar:", "pitt.search.semanticvectors.CompareTerms", "-queryvectorfile","/Users/feralvam/termvectors.bin","term1","term2"])
I've managed to install StatET into eclipse, and I have a Java project called "Test" with some code in there. I'd like to be able to keep a .R file in that project folder and run it as a stand alone R script, seperate from the Java program. How can I do this? If I try to highlight some R code in a .R file and run it, it says "No session of R is active in the current workbench window."
Update:
I added a run configuration and I now have the following error in a pop up box when I try to run the R script:
Launching the R Console was cancelled, because it seems starting the R engine failed.
Please make sure that R package 'rj' (1.0.0 or compatible) is installed and that the R library paths are set correctly for the R environment configuration 'R'
You need to first start an R console from within Eclipse. Select Run -> Run Configurations... from the menu bar. If you have not already created an R configuration, you can create a new one by right-clicking on R Console. For more information, Longhow Lam put together a nice guide (PDF).
EDIT:
Regarding your new error message, make sure rj is installed in R by running one of these commands in the command-line version of R. For the current StatET 2.0:
install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.0")
For the development StatET 3.0:
install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.1")
For the old StatET 0.10:
install.packages("rj", repos="http://download.walware.de/rj-0.5")
EDIT2
Its now
install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-2.1")
Also see http://www.walware.de/it/downloads/rj.02.01.html
Just had same error message and finally found that it's due to the lack of privileges to write to the library directory under R. Therefore although Eclipse shows that RJ is installed, it's actually not.
re-installed RJ to a user directory and added the directory to the R console config, it worked.
For me I have to change in run/run configuration/launch type to put the value "Rterm" because it was to RJ by default and do the same config that jthetzel said in R-config -> configure -> add -> + -> try to find automaticly -> apply.