7

Its being a real nightmare to install rjava on my Mac.

My setup:

MacOS 10.9.5
Java: 7u71 (64 bits dowloaded from Oracle site)
R: R version 3.1.1 (2014-07-10)

First, in the command line I ran the

sudo R CMD javareconf

Then, I ran inside R:

install.packages('rJava')

The error in the end of the compiling is this:

JavaVM -F/opt/local/Library/Frameworks/R.framework/.. -framework R -llzma -lm -liconv -licuuc -licui18n
ld: library not found for -licuuc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
* removing ‘/Users/costa/Library/R/3.1/library/rJava’

I tried Java 8 and the Mac default java and also got the same error.

Ideias?

hhh
  • 50,788
  • 62
  • 179
  • 282
Menthor
  • 71
  • 1
  • 2
  • I believe I had to install the snow leopard build and it works fine – rawr Nov 05 '14 at 11:57
  • I tried that using this version: http://support.apple.com/kb/dl1573 but I could not install (my Mac is a 10.9.5) – Menthor Nov 05 '14 at 21:08
  • `openxlsx` is a nice alternative that doesn't depend on Java. https://github.com/cran/openxlsx – James Dec 08 '15 at 16:08

6 Answers6

4

What I did (using macports R) as root (sudo bash):

  • edit /opt/local/Library/Frameworks/R.framework/Resources/etc/Makeconf and change the line

    LIBS =  -llzma -lm -liconv -licuuc -licui18n
    

    to

    LIBS =  -llzma -lm -liconv
    
  • install the original 1.6 Mac Java

  • export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

  • run R CMD javareconf

Now you can start R and do a install.packages("rJava"). Using the 1.6 version of Java made sure that also RStudio can load the rJava package.

If you do not plan using RStudio, you can also use Java 1.8

Jan Sila
  • 1,554
  • 3
  • 17
  • 36
  • worked for me just to change the flags in the `Makeconf`file! Also, you might need to run `R CMD javareconf` with `sudo`. – Jan Sila Jul 24 '17 at 15:20
1

I had the same error on my computer (Mac OS 10.9.5, Java 1.8.0_11, R 3.1.1). Installing the newest Java JDK from Oracle (1.8.0_25) didn't solve the problem (yet). However, after updating Java, installing R 3.1.2 solved the problem for me. After running install.packages("rJava"), this works:

> library("rJava")
> .jinit() # this starts the JVM
> s <- .jnew("java/lang/String", "Hello World!")
> .jcall(s,"I","length")
[1] 12

Do note that updating the JDK is something different from the Java version in the GUI Java Control Panel, accessible through the System preferences. The latter is only the JRE for the internet browser plugin.

Joqer
  • 11
  • 3
1

I was actually able to avoid editing my environment completely by using the Mac binary to install rJava on my Macbook (running OSX Yosemite and R version 3.2.3). First, do the following in R to install rJava:

install.packages("rJava", type = "mac.binary")

Presumably independent of this, for some reason I couldn't install xlsx until I first installed the xlsxjars dependency. So do the following in R:

install.packages(c("xlsxjars", "xlsx"))

And with those two commands, xlsx appears to install just fine on a mac!

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Dr. Arun
  • 176
  • 6
1

This worked for me:

sudo R CMD javareconf

Then, in the R interpretor:

install.packages('rJava', type='source')
install.packages('xlsx', type='source')
bsky
  • 19,326
  • 49
  • 155
  • 270
0

I had the same issue. I'm using OS X Yosemite and initially had installed R through homebrew

I performed the following steps to fix it:

  1. Closed all instances of R
  2. In my terminal shell, ran sudo R CMD javareconf
  3. Opened up R from my terminal and ran:

    install_packages("rJava")

    install_packages("xlsx")

Ashwin Balamohan
  • 3,303
  • 2
  • 25
  • 47
0

Using the old Java SE 6 I was able to get rJava compiled by running javareconf as follows:

JAVA_HOME=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home \
JAVA_CPPFLAGS=-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/ \
r CMD javareconf
stephenhouser
  • 325
  • 3
  • 13