e-kotov / rJavaEnv

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

try to address: cannot install rJava from source without javareconf with admin privileges #16

Open e-kotov opened 5 months ago

e-kotov commented 5 months ago

Test report for macOS (Apple Silicon/aarch64/ARM) (with R packages installed from source)

System:

sw_vers
#> ProductName: macOS
#> ProductVersion: 14.5
#> BuildVersion: 23F79

uname -m
#> arm64

Test sequence:

1. Install Homebrew from https://brew.sh/

2. Install R and RStudio

brew install r
brew install --cask rstudio

3. Check if there is Java in vanilla macOS

which java
#> /usr/bin/java

java --version
#> The operation couldn't be completed. Unable to locate a Java Runtime.
#> Please visit http://www.java.com for information on installing Java.

4. Run RStudio

5. Check if {rJava} can be installed with Java installed using {rJavaEnv}

install.packages("remotes")
remotes::install_github("e-kotov/rJavaEnv")
library(rJavaEnv)
java_quick_install(21)
java_check_version_cmd()

install.packages("rJava")

results in:

configure: error: Java Development Kit (JDK) is missing or not registered in R Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.
If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
ERROR: configuration failed for package 'rJava'
* removing "/opt/homebrew/lib/R/4.4/site-library/rJava'
Warning in install.packages :
installation of package "rJava' had non-zero exit status

6. Try javareconf

In Terminal, without admin rights:

export JAVA_HOME=/Users/user/Library/Caches/org.R-project.R/R/rJavaEnv/installed/macos/aarch64/21
R CMD javareconf -e
install.packages("rJava")

Fails.

In Terminal, with admin rights:

export JAVA_HOME=/Users/user/Library/Caches/org.R-project.R/R/rJavaEnv/installed/macos/aarch64/21
R CMD javareconf
install.packages("rJava")

Succeeds! {rJava} is built from source!

Verdict

Overall, {rJavaEnv} package works as expected, but some manual actions are still required from the user. Specifically, the user needs to close R/RStudio and run two commands in the terminal with admin privileges to reconfigure Java.

Originally posted by @e-kotov in https://github.com/e-kotov/rJavaEnv/issues/15#issuecomment-2198244577

e-kotov commented 5 months ago

Suggested solution

Check .Platform$pkgType.

Other OSes

It will probably be exactly the same for Linux and Windows.