s-u / rJava

R to Java interface
https://RForge.net/rJava
235 stars 77 forks source link

Can rJava install openjdk during the installation? #332

Open moomoofarm1 opened 1 month ago

moomoofarm1 commented 1 month ago

As stated in the title.

e-kotov commented 1 month ago

@moomoofarm1 see https://github.com/e-kotov/rJavaEnv alternatively:

s-u commented 1 month ago

I don't see this a something that it should do. The user should install whichever Java version(s) they intended to use - rJava should not make the call. The only option I could see is if no JRE is found at initialization time then to either point to a way to install it or offer a local installation after a prompt with version options (sadly, Java has descended into the Python nightmare world by constantly breaking compatibility so you have to carefully select the version that works with the code you intend to run). rJava was originally designed to provided consistent support for R, so it is no different than other tools like compilers and libraries in R that needs to be present before they are used.

That said, there is an issue on allowing run-time loads of JVM (see #334) - so in that world it would make it more sense to allow run-time installs, but that is different from this issue.

moomoofarm1 commented 1 month ago

Thanks for the answers. I would really appreciate it if the package can install it automatically and keep the installation underneath. R users like me are not familiar with the details.

e-kotov commented 1 month ago

@moomoofarm1, the problem is, there are multiple versions of Java that may be required by various packages that you use. So you have to decide which Java version you need to install by reading the recommendations in the package documentation. The author of a particular package may provide you with instructions on how to install the exact version of Java that you need to use their package. For example, this is something the authors of {r5r} have done here. They rely on {rJavaEnv} to quickly install the Java they need (version 21) for {r5r} to work.

So even if {rJava} would have a function to install Java, you would still need to do a little bit of work.

If you want the easiest method that will take into account your OS and processor type, please do:

install.packages('rJavaEnv')
rJavaEnv::java_quick_install(version = 21)

Or whichever Java version you need depending on the package you plan to use.

Preferably, restart R after doing this. If you are on Linux (or on macOS/Windows, but you chose to install packages from source), you may need to remove {rJava} first, install Java as I noted above, and then re-install {rJava}.