3

I realise this is not really a programming question, but I am hoping that one of the very experienced NetLogo people here can see what I am doing wrong, especially as many of you work in Java and I don't.

I am trying to connect up the R-extension so I can use R libraries to do some tricky network stuff. I am using Windows 7. The detailed installation instructions describe three system variables that must be set. I have done so and echoing them from the command prompt, R_HOME and JRI_HOME connect to what appear to be the appropriate directories and my PATH includes the R bin.

variables check

Step 4 of the installation instructions opens an R terminal from command line and that works fine. Similarly, loading the rJava library from within that terminal (that is step 6, entering library(rJava)) returns the appropriate message. The check on java versions (step 9) returns the appropriate 64 bit responses, exactly the same as in the documentation except that my vm version is more recent.

Testing it all together (step 12) opens NetLogo and I type extensions [r] but the check tick closes it immediately. According to the documentation, this is an error with R_HOME and PATH, but I can't see it. In the command line, I get an error Cannot find JRI native library! Please make sure that the JRI native library is in a directory listed in java.library.path followed by many java errors.

Is there an environment variable I forgot to set? Do I need to actually add something to the java.library.path even though that's not described in the documentation?

UPDATE

On further investigation, there is an extension called rsystemcheck that is shipped with the r extension. Installing that [note for others who have this problem, simply move the folder into the extensions folder], it appears that my computer has (at least) two versions of Java installed. This is not terribly surprising as the Java update process doesn't really clean up and lots of programs install additional versions of the runtime.

The 'Check java' tool reports that I have v1.8.0_51 and v1.6.0_45 installed and that if one is 32bit and the other is 64bit then the R extension won't work.

Ratting around in my file system - v1.8.0_51 is definitely 32bit. I also have v1.7.0 64bit (a new one!) installed. I can't find v1.6.0_45 directly, but I think this is the version that is in the jre folder of the NetLogo installation.

Furthermore, trying to install NetLogo without the VM and pointing to my JRE does not work because NetLogo requires the JRE to be 32bit. Further, uninstalling java and replacing with the 32bit version does not work because I use 64bit R.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • JenB, I consider you one of the very experienced NetLogo people here! If you don't get an answer, the [netlogo-devel](https://groups.google.com/forum/#!forum/netlogo-devel) Google group might be appropriate, though I realize it's not a development question. – Mars Oct 27 '15 at 04:07
  • I don't use Windows much. Could there be a file permission problem, or something like that? – Mars Oct 27 '15 at 04:13
  • thanks Mars. Shouldn't be a file permission problem, I would expect that to be a different error message (something like denied rather than cannot find). I know other people have had problems with connecting to R. There's a very similar Mac question http://stackoverflow.com/questions/27190975/netlogo-r-extension-installation-error-in-mac-os-x-yosemite?rq=1 and the installation would be difficult for someone who has no idea what an environment variable is so there's some that are just not doing all the steps, but my variables look fine. I just have absolutely no experience with jar files. – JenB Oct 27 '15 at 07:23
  • You might try emailing a link to this question to the authors of the R extension. I'm not sure if they hang out here. – Seth Tisue Oct 27 '15 at 15:08
  • updated for java version incompatibility issues – JenB Oct 28 '15 at 12:53

2 Answers2

1

okay, solved (if somewhat unsatisfactorily). I am leaving this here because I imagine other people using Windows want R and NetLogo to talk to each other.

The problem is that NetLogo requires 32 bit Java. I have no idea how the developers of the R extension(s) got screenshots with 64bit R, but what you really need to do is use 32 bit R.

(1) uninstall 64bit java and instead install 32bit java

(2) add the 32bit R installation

(3) leave the environment variable %R_HOME% as in instructions

(4) add %R_HOME%\bin\i386 to Path

The important bit is step (4), which makes the R extension find the 32 bit installation of R. The R installation directory has two bin subdirectories, one for 64bit (x64) and one for 32bit (i386). The Path needs to find the 32 bit version.

Step (1) may be optional - I simply don't have the java understanding necessary to work out how to deal with 32 and 64 bit versions of java.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • re: 64-bit Java on Windows, I see you found https://github.com/NetLogo/NetLogo/issues/423. adding the link here in case anyone else is interested – Seth Tisue Oct 28 '15 at 15:34
  • see the "doc" folder of the R-extension. There are two pdf files, one of them explaining how to get NetLogo running with 64-bit Java. – Jan C. Thiele Dec 03 '15 at 20:35
  • With the new 64bit java available with NetLogo, it is now easier to use the 64bit R as well. Two tricks. (1) at step 12 in the documentation, make sure you go into the 'app' folder within NetLogo before typing `java -jar ...` as the NetLogo jar file is now in a different place. (2) If running Win 8.1, you might also need the registry key in the answer at http://stackoverflow.com/questions/16428098/groovy-shell-warning-could-not-open-create-prefs-root-node – JenB Jan 13 '16 at 20:45
0

I think the key is to make sure all your software is either 64 bit or 32 bit. I can open R from NetLogo successfully by using all 64 bit R, Java and NetLogo. My working code can be found here. https://raw.githubusercontent.com/tonysdatamodels/netlogo.in.r/main/open%20netlogo%20in%20r. I also have a short video on youtube video explaining how to successfully open NetLogo from R https://www.youtube.com/watch?v=zWMdaTEPTOc .