Reputation: 417
I am trying to load a Netlogo model in headless mode with RNetLogo. The model uses the rnd extension which is added to the model by extensions [rnd]
. If I try to load the model with NLLoad(model.path)
I get this error:
NLLoadModel(model.path)
[1] "Java-Object{Can't find extension: rnd at position 79 in }"
Error in NLLoadModel(model.path) :`
Unfortunately, I cannot find anything in the documentation of NLLoad.
I tried setting the the working directory to the Netlogo directory: setwd("/Applications/Netlogo 6.0.1")
. This changes the error to
[1] "Java-Object{There was a problem while reading extension rnd at position 79 in }"
Fehler in NLLoadModel(model.path) :
The rnd
extension is safe and sound in the extensions folder: /Applications/Netlogo 6.0.1/extensions/rnd.jar
.
Upvotes: 2
Views: 694
Reputation: 124
On Mac, this issue can be fixed as follows:
For each NetLogo extension in use, copy and paste that folder into the directory containing the .nlogo model you are attempting to run.
For example, for the rnd
extension, copy the folder /Applications/NetLogo 6.0.4/extensions/nw
to the enclosing folder set in model.path
. NLLoadModel(model.path)
should now execute without this error.
This solution is based on the Extensions Guide of the NetLogo 6.0.4 User Manual (emphasis added):
NetLogo will look for extensions in several places:
- In the folder of the current model.
- The extensions folder located with the NetLogo installation. For typical NetLogo installations:
- On Mac OS X: /Applications/NetLogo 6.0.4/extensions
- On 64-bit Windows with 64-bit NetLogo or 32-bit Windows with 32-bit NetLogo: C:\Program Files\NetLogo 6.0.4\app\extensions
- On 64-bit Windows with 32-bit NetLogo: C:\Program Files (x86)\NetLogo 6.0.4\app\extensions
- On Linux: the app/extensions subdirectory of the NetLogo directory extracted from the installation .tgz
It's unclear to me why the check to /Applications/NetLogo 6.0.4/extensions
doesn't work, but at least there's a solution!
I encountered the same issue with the nw
extension in NetLogo, receiving a nearly identical error:
> NLLoadModel(model.path)
[1] "Java-Object{Can't find extension: nw at position 13 in }"
Error in NLLoadModel(model.path) :
So the issue seems to apply to all extensions.
Upvotes: 0
Reputation: 156
I made this work (using the CSV extension) by copying the contents of the CSV extension folder directly into the app
folder.
I'm working under GNU/Linux. This method may work better for OSx users, too. I'm guessing that this isn't working as expected because there is no "installation" of RNetLogo that sets the classpaths for us. We explicitly tell R where to find netlogo-x.x.x.jar, but not any of the extensions.
Upvotes: 0
Reputation: 10291
Responding to your comment- that's too bad, but it was worth a shot. Maybe that approach only works with running headless from the command line. I also just clued in that it looks like you're on Mac- I'm running Windows so my solutions most likely won't work for you. Did you read the "Note for MAC users" in the RNetlogo documentation?
Anyway, I got a simple version of this working on Windows so I thought I'd show you my setup and see if that helps at all. This is the folder with my model, as well as the app
folder containing the netlogo-6.0.1.jar
and the extensions
folder containing all the extensions and their folders (copied whole from within the app
folder):
test_rnd.nlogo
is as follows:
extensions [ rnd ]
globals [ pcolor-list ]
to setup
ca
reset-ticks
ask patches [
set pcolor random 10 + 50
]
end
to go
check
tick
end
to check
set pcolor-list []
repeat 10 [
ask rnd:weighted-one-of patches [ pcolor ] [
set pcolor-list lput pcolor pcolor-list
]
]
end
Then, in R:
library(RNetLogo)
nl.path <- "C:/test_rnetlogo/app"
model.path <- "C:/test_rnetlogo/test_rnd.nlogo"
NLStart(nl.path, gui = FALSE, nl.jarname = "netlogo-6.0.1.jar")
NLLoadModel(model.path)
NLCommand("setup")
NLCommand("Go")
test <- NLReport("pcolor-list")
> print(test)
[1] 53 53 50 57 50 53 50 58 58 51
So in this example, at least in Windows, just having the extensions folder, the app folder, and the model file itself all in the same location seems to have worked. Sorry I don't know a fix for the Mac, hopefully someone else has a proper solution.
Upvotes: 2