1

It seems that the last java version makes rJava not able to load or compile / install.

Is there any way I can have java8 and java9 installed and force rJava or R use the java8 version?


Edit: It's been suggested that perhaps this thread is the solution to my problem, but it isn't. Since I need to use a lower version, not the new one. Seems that it's possible to tell R where is the java_home, but I don't know how.

zx8754
  • 52,746
  • 12
  • 114
  • 209
lpuerto
  • 301
  • 4
  • 16
  • 5
    Possible duplicate of [rJava is not picking up the correct Java version](https://stackoverflow.com/questions/28133360/rjava-is-not-picking-up-the-correct-java-version) – achAmháin Sep 28 '17 at 09:30
  • It said *possible* :) anyway, can you try putting Java8 first on the path? – achAmháin Sep 28 '17 at 09:36
  • Do you mean in the system path? Then... it's a not a solution since it's like I only have java8, isn't it? – lpuerto Sep 28 '17 at 09:37

1 Answers1

2

Take a look here: R, Java, rJava and macOS adventures and here: R 3.4, rJava, macOS and even more mess ;)

R, Java and proper settings that make every piece of software happy can be a struggle ;)

You need to play with JAVA_HOME, R CMD javareconf, and sometimes even compilation of rJava from sources.

If you need a specific version of Java just for R, you can always play with something like this.

First, get the list of JVMs

/usr/libexec/java_home -V
Matching Java Virtual Machines (4):
    9, x86_64:  "Java SE 9" /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
    1.8.0_144, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
    1.8.0_111, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
    1.7.0_80, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home

Then, pick one just before starting R

-- start_R_with_Java_8.sh --
#!/bin/bash
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0_144)
export PATH=$JAVA_HOME/bin:${PATH}
R

This way, in system you will have Java 9, while for R, you will have 1.8.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45
  • Thanks a lot for the contribution and I think I'm going to bookmark it for future reference, but it isn't the exact solution I'm looking for. Right now, everything looks up and running, but decided to uninstall Java9 and reinstall Java8, the same they are using in that example. I don't have to configure a lot of things, like in the example, to make things work with Java8. The problem here seems to to be that rJava is not really compatible with Java9. For that reason I was looking for way to have both and use the lower version for R and the updated one for the rest of the things. – lpuerto Oct 02 '17 at 08:51
  • But since one have to be editing JAVA_HOME to properly work with R, things seems to be really complicated to have that setup. The other way around seems to be really easy. I mean, make R to use the last version and have more versions for other things if necessary. I tried also jenv, but seems to don't be really compatible with R. – lpuerto Oct 02 '17 at 08:53
  • 1
    In that case, I think you can make sure JAVA_HOME points to Java8 (before you run R). So, you can make a wrapper script for R where you simply set JAVA_HOME to Java 8 and run R. For the rest of system, it will still be Java 9. Also, you might need to reconfigure R to use Java 8 again. – Oo.oO Oct 02 '17 at 08:56
  • That's a solution that perhaps I'll try in close the future, if they don't fix rJava. I've already spend an afternoon "playing" with the issue and I really don't have a lot of time for this. And right now, I don't really need to update to Java9 unless is a matter of security. – lpuerto Oct 02 '17 at 09:10