tags:

views:

215

answers:

4

When installing rJava using the install.packages("rJava") command I get the following error:

checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : '-I/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include -I/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include/linux'
java libs   : '-L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64/server -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64 -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm'
checking whether JNI programs can be compiled... yes
checking JNI data types... configure: error: One or more JNI types differ from the corresponding native type. You may need to use non-standard compiler flags or a different compiler in order to fix this.
ERROR: configuration failed for package ‘rJava’

I have the Java JDK installed and java -version returns the following:

$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)

When Googling around for the error I see that others are having the same issue but not finding a solution other than "install the whole JDK, not just the JRE" which I have done.

The other thing I read was to run sudo R CMD javareconf which runs quite happily with no errors.

Any ideas what my problem is?

[[EDIT]] It's been a few months since I had this problem. I had initially solved this by editing my Java paths, as illustrated in the answer I posted below. I recently ran into the same issue on a new Ubuntu install. I tried Dirk's recommendation to use apt-get to install the rJava package. It worked perfectly. What I failed to appreciate initially is that installing packages using the Ubuntu apt-get method is fundamentally different than just loading the same package using install.packages() inside of R. The Ubuntu packages solve some issues which I didn't realize or appreciate.

+5  A: 

Turns out my problem was an issue with my JAVA_HOME environment variable. Yes, shocking I know. My initial setting for PATH and JAVA_HOME looked like this:

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

And I added /jre so it now looks like this:

export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export PATH=$PATH:$JAVA_HOME/bin

Everything in Java seemed to work fine without the /jre but rJava would not. Odd.

JD Long
Keeping to the true meaning of "stack overflow" by creating a question -> answer infinite loop---I like it.
DrewConway
Thanks. Doing my bit to make sure future Google users can find answers to their R questions!
JD Long
+3  A: 

Wouldn't

apt-get install r-cran-rjava

have been easier? You could have asked me at useR! :)

Dirk Eddelbuettel
I'll test that and see if it works! I figured out the environment var issue during one of the keynotes ;) I just posted here because it was really hard to search for in google. I'm hoping this saves the next guy some time.
JD Long
The point of Ubuntu and Debian is that you should't have to google in the first place --- it should "just work" using the proper packages. Make your life easier and use packages where you can. I presume you used Ubuntu's Java packages too?
Dirk Eddelbuettel
Dirk, you ask these questions like I have any idea what the hell I did. If I recall, I had trouble installing Java using apt-get so I built from source and that's probably the source (all puns intended) of my problems. Of course it might just be bad karma.
JD Long
A: 

I am 'the next guy' whose time you saved JDLong. Funny that I run into the same bunch of expert aRrr'ers, Dirk, Drew and JDLong. Gracias!

Vishal Belsare
@Vishal: Great to hear that this helped; for future reference: "this is a comment, not an answer."
Shane
@vishal, glad this gave you some help. @shane, you're correct. But let's not slow a guy down from giving me kudos ;)
JD Long
Shane: sorry for posting that as an answer. I was a tad excited to get Long's answer at about 3am and getting my Java right..
Vishal Belsare