tags:

views:

734

answers:

3

Hi,

I installed/uninstalled java jre/jdk now many times and finally installed the older version 1.6.0_17 which is now located at "C:\Program Files\Java\jre6\bin". Now after all if I call 'java -version' within R i can see that R is looking for Java at the old path which is now wrong. The question is: Why is R looking for Java at the wrong path even so the windows path is set correctly? There are no double entrys within the windows path as far as I can see and I restarted R as well as Windows more then once since then. Any Ideas where R takes the wrong path from?

On windows shell:
$>set
[..]
OS=Windows_NT
Path=C:\Program Files\Java\jre6\bin;
[..]

$> java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

within R:
$>system("java -version")
Error: could not open `C:\Program Files (x86)\Java\jre6\lib\i386\jvm.cfg'

+1  A: 

You're assuming that R is looking at the windows path, but the code is telling you that it's not. So check your assumption: R is getting the path somewhere else.

If I open up a command shell on my Windows machine and type "java -version" I get this:

C:\>java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

If I check the PATH on my machine, I get (edited for clarity):

C:\>set path
Path=;C:\JDKs\jdk1.6.0_13\bin;

If I open up R version 2.8.1 and run system("java -version") I get this:

> system("java -version")
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)
>

So, like I said, R is not using my path to find java.exe. It's using something else.

duffymo
The OP is running the `system` command from within R, which ` invokes the OS command specified by 'command'.`. In other words, it is using the path.
Shane
@Shane, my point is that his own post tells us what the Windows PATH is set to, yet R itself is not using that value. Hence my comment that it is NOT using what PATH points to. "In other words, it is using the path. - R disagrees with you.
duffymo
@duffymo: thanks for that additional edit; I get the same behavior. Very strange! `system` should just be running the operation on the cmd prompt.
Shane
Yes, thats exactly the point! The question is how does R get the java path.
Veit
@Shane `system` use command promt, but there are two of them: 32 and 64-bit. Check my answer.
Marek
@Marek: Thanks, this has been helpful. The OP never stated they were using 64-bit, although I probably should have assumed that from the error message.
Shane
@Veit - the path that R is getting on my system appears to come from the registry. The only JDK that I have installed is jdk1.6.0_13; the version 1.6.0_15 is a JRE.
duffymo
A: 

You may also need to check the registry, R may have its own setting. You can also start regedit and do a search on the path to binary that it is starting.

M. Jessup
A: 

You problem depends on 64/32 bit versions.
You run 32-bit R, which use 32-bit command prompt and find 32-bit java. If you use 64-bit R then it runs 64-bit command promt and proper java.

You could check it by run 32-bit command promt (following this post):

  1. Click Start.
  2. Type %windir%\SysWoW64\cmd.exe in Start Search box.
  3. Press Enter.
  4. Type java -version

In my system it fails because I don't have 32-bit java. With standard cmd.exe I get proper path.

For possible solution there are two ways. Install 32-bit R and 32-bit Java or 64-bit R (which is officially supported from 2.11 version) and 64-bit Java. On my system (64-bit Windows 7) I've got both sets, so on 32-bit combination I get:

> system("java -version")
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

And on 64-bit:

> system("java -version")
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) 64-Bit Server VM (build 16.0-b13, mixed mode)

On 64-bit version you could call 32-bit Java using 32-bit cmd:

shell(
    "java -version",
    shell = file.path(Sys.getenv("windir"),"SysWoW64/cmd.exe")
)
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

About Shane's comment I think the question is how R get path to 32-bit cmd. Because I can't find a way to call 64-bit cmd on 32-bit R.

Marek
You are right! ... So compiling the 64-bit R version is the only solution? I thought the R 32-bit version should be fine.
Veit
@Veit You could use full path to java as Leo Alekseyev states in his comment to your question. But if it helps you depends on what you try to do.
Marek
And there is coming official 64-bit release of R: http://cran.at.r-project.org/bin/windows64/
Marek
@Marek: out of curiosity: do you know where the `path` for the 64-bit cmd.exe comes from?
Shane
using the R 64-bit version does not seem to help me. If I call "library(rJava)" within the 64bit R version the "Error: package 'rJava' is not installed for 'arch=x64'" returns. So I still have to fix the java path R is using. Or are there any other solutions?
Veit
@Shane I tried to find it but without success. I guess that Windows itself choose cmd version based on application type (32/64), but it is only guess.
Marek
@Veit I just do `install.packages("rJava");library(rJava)` and don't have errors (built 2010-03-04 r51206). I guess you overwrite you R instalation and don't update packages with `checkBuilt=TRUE`. If not try to install R in fresh directory and then install rJava.
Marek
@Marek: I can not use <code> install.packages("rJava") </code> because of proxy settings, so I had to use "Install packages from local zip files" ... might this be a problem?
Veit
@Veit If you do'nt get it from here: http://cran.at.r-project.org/bin/windows64/contrib/r-devel/ then yes. Packages must be built under proper version of R.
Marek
@Marek: hmmm... there seems to be no 'rJava' or am I blind...
Veit
@veit My mistake, its here http://www.stats.ox.ac.uk/pub/RWin/bin/windows64/contrib/2.11/. But if you have proxy problems try to set `setInternet2(use = TRUE)`
Marek