e-kotov / rJavaEnv

Java Environments for R Projects
http://www.ekotov.pro/rJavaEnv/
Other
12 stars 1 forks source link

44 interface that doesnt affect rprofile #46

Closed e-kotov closed 2 months ago

e-kotov commented 2 months ago

Implementing #44 and partially #45 .

@hadley, so far without checking for existing JAVA_HOME, just pure proof of concept.

To test:

if (!requireNamespace("remotes", quietly = TRUE)) {
  install.packages("remotes")
}

remotes::install_github(
  "e-kotov/rJavaEnv@44-interface-that-doesnt-affect-rprofile",
  force = TRUE, dependencies = TRUE
)

library(rJavaEnv)
getOption("rJavaEnv.valid_major_java_versions")

use_java(8)
"8" == java_check_version_cmd(quiet = TRUE)
"8" == java_check_version_rjava(quiet = TRUE)

use_java(11)
"11" == java_check_version_cmd(quiet = TRUE)
"11" == java_check_version_rjava(quiet = TRUE)

use_java(17)
"17" == java_check_version_cmd(quiet = TRUE)
"17" == java_check_version_rjava(quiet = TRUE)

use_java(21)
"21" == java_check_version_cmd(quiet = TRUE)
"21" == java_check_version_rjava(quiet = TRUE)

use_java(22)
"22" == java_check_version_cmd(quiet = TRUE)
"22" == java_check_version_rjava(quiet = TRUE)

# and back to 8, to see if cached installation setting is instant and skips download and install/unpacking
use_java(8)
"8" == java_check_version_cmd(quiet = TRUE)
"8" == java_check_version_rjava(quiet = TRUE)

# to reset downloaded files
java_clear("distrib", delete_all = TRUE)
java_clear("installed", delete_all = TRUE)
e-kotov commented 2 months ago

This was just what I was imagining. Thanks!

@hadley thanks for the review, tips and suggestions! Implementing this actually caused some code cleanup, which is also great. And the feature itself is super useful, thanks for a great request! It will also work fit well with my planned vignette on how rJavaEnv can be used with {targets} and {callr}. I'll revise once more this week and submit this version to CRAN.