Matching 64 bits versions but error loading rJava

孤街醉人 提交于 2021-01-28 09:01:16

问题


I have set the JAVA_HOME to JAVA_HOME="C:\Program Files\Java\jre1.8.0_251".

I have installed a 64 bits version of Java which is matching with my 64 bits R (version 4.0.2) and Windows 10 Home.

Error remains in loading rJava as below:
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/my_R_library/rJava/libs/x64/rJava.dll':

I tried to reinstalled JAVA and R, rJava cannot be loaded.
I tried the function find.java(), it runs properly

Is there any suggestion to deal with the problem?


回答1:


My problem finally solved. Since my Windows is a Chinese version, it cannot recognise any Chinese characters in the paths if I installed an English version. What I have done is just installing a Chinese version R, no need to set the JAVA_HOME at all. I hope this can hope the potential use of R with their own langauge based Windows.




回答2:


Once Java is installed on a Windows based PC, one must ensure it is configured in the operating system in a way that R can access it. First, check the Java Control Panel. In the windows 10 search bar, search for Configure Java, and then press from the list of choices for the Java Control Panel.

From the Control Panel main window, select the Java tab,

and then press the button.

At this point you should see at least one row of information that illustrates the version and location where you have Java installed.

If your version of Java isn't listed, you can use the > or buttons to find or add the version that had been installed but is not listed.

Exit the Java Control Panel, open a command window (type cmd in Windows search bar), and type

 java -version

This should display the version of Java that is visible to Windows, as illustrated below.

Next, we need to confirm that Java is accessible within RStudio. Open RStudio and use the system() function to check the version of Java.

  system("java -version")

We should receive the same result as we did with the Windows command line version of java -version.

> system("java -version")
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
[1] 0

At this point, one should be able to install rJava. However, if Java isn't accessible, we'll need to use the Sys.setenv() function to set the path for Java home.

# set JAVA_HOME to directory listed in Configure Java app, such as 
# C:\Program Files\Java\jre1.8.0_231
Sys.setenv(JAVA_HOME="C:/Program Files/Java/jre1.8.0_231")

...and now we should be able to install rJava.

 install.packages("rJava")


> install.packages("rJava")
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/rJava_0.9-12.zip'
Content type 'application/zip' length 1214816 bytes (1.2 MB)
downloaded 1.2 MB

package ‘rJava’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\leona\AppData\Local\Temp\RtmpWGyEQp\downloaded_packages
> 


来源:https://stackoverflow.com/questions/62740681/matching-64-bits-versions-but-error-loading-rjava

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!