1

I want to install rJava but this fails with the following suggestion:

Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run "R CMD javareconf" as root.

ERROR: configuration failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rJava’
* restoring previous 
‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rJava’

Hence, I follow this suggestion (and the one everyone else seems to suggest) and run R CMD javereconf in the terminal but now I get the message that zsh: command not found: R.

How can I get R CMD javereconf to work? Thanks.

EDIT: While I followed the blogpost suggested by @Till, I still struggle to run R CMD javereconf (same error). In the meantime, I figured that I should mention that I'm using MacOS Big Sur with an Apple M1 Chip. When typing R.home() RStudio returns /Library/Frameworks/R.framework/Resources/R.

Thomas
  • 1,392
  • 3
  • 22
  • 38
  • 1
    [This](https://zhiyzuo.github.io/installation-rJava/) might help. – Till Apr 29 '21 at 21:07
  • Also you can read more about running R from the command line on a Mac at: https://stackoverflow.com/questions/44336345/running-r-from-mac-osx-terminal/44343563. The default install doesn't add R to your global path. – MrFlick Apr 29 '21 at 21:54
  • Can you follow the steps that i have used on https://stackoverflow.com/a/66904735/11724419 ? It worked for me – Ege Can May 07 '21 at 12:36

2 Answers2

2

There is currently a bug in CRAN's R installation package that results in it not correctly installing symbolic links to R and Rscript for commandline use. I've just verified this by inspecting the postflight script in their 4.0.5 installation package.

Basically, there's a problem wherein the uname check doesn't know about operating system releases of 20 and above.

If your uname -r release version is over 20, this would explain why the installation silently failed. My recommendation would be to manually create the symbolic links the package is supposed to create by doing something like this:

if uname -r | grep '^2' >/dev/null; then
    ## 15.0 and higher don't allow messing with /usr/bin
    ## so use /usr/local/bin instead
    if [ ! -e /usr/local/bin ]; then
        mkdir -p /usr/local/bin
    fi
 
    cd /usr/local/bin

    # create convenience links to R and Rscript
    rm -f R Rscript
    ln -s /Library/Frameworks/R.framework/Resources/bin/R .
    ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .
fi

I'm going to file a bug with R-project shortly.

Yuri Broze
  • 136
  • 3
0

Find the location of R and Rscript on your disk by running R.home() on Rstudio's R console. Then, follow this guide and copy the returned location from R.home() and paste on a new line on /etc/paths.

Then, restart the terminal and run R CMD javareconf

Ege Can
  • 195
  • 1
  • 10