1

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?

Dave2e
  • 22,192
  • 18
  • 42
  • 50

2 Answers2

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.

  • Nice work, Jecko. That's not an easy problem to solve, a language incompatibility between the operating system and the software installed atop the operating system. Definitely worth an upvote! – Len Greski Jul 09 '20 at 10:27
0

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,

enter image description here

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.

enter image description here

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.

enter image description here

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
> 
Len Greski
  • 10,505
  • 2
  • 22
  • 33
  • 1
    First of all, thanks Len Greski for your advice. Following your instruction and cross checked, both my Windows and R-studio show the same Java version. rJava installed properly but the problem remains. Related modules cannot be found to load the shared object rJava.dll. Will my path setting in R-studio get wrong?Sys.setenv(Path= "C:\\Program Files\\Java\\jre1.8.0_251;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Users\\jecko\\AppData\\Local\\Microsoft\\WindowsApps;C:\\my_R_library") – Jecko Cheng Jul 07 '20 at 12:58
  • @Len Greski I followed all the steps, java versions match, but problem remains. Unfortunately the solution by Jecko Cheng did not hals, as i do not have chinese version – AAAA Jul 09 '20 at 09:06
  • 1
    @MariuszSiatka - At this point you should submit a defect report to the author of rJava on the [rJava](https://github.com/s-u/rJava/issues) Github site. Also, which language version of Windows are you using? – Len Greski Jul 09 '20 at 10:26
  • @Len Greski I am using Polish version. I will report the issue – AAAA Jul 09 '20 at 10:59
  • @MariuszSiatka - I just discovered that R supports the Polish language. Therefore, if you reinstall R with Polish language support, the Java install should work with your operating system, as it did for Jecko with Chinese. – Len Greski Jul 21 '20 at 21:25