Learn R Programming

RNetLogo (version 0.9.4)

RNetLogo-package: Provides an interface to the agent-based modelling plattform NetLogo

Description

Interface to use and access NetLogo from R using either headless (no GUI) or interactive GUI mode. Provides functions to load models, execute commands, and get values from reporters. Mostly analogous to the NetLogo Mathematica Link http://ccl.northwestern.edu/netlogo/docs/mathematica.html.

Arguments

Details

ll{ Package: RNetLogo Type: Package Version: 0.9.4 Date: 2013-01-02 License: GNU GPL v2 LazyLoad: yes } Start by creating a NetLogo instance by using NLStart. Then load a model with the function NLLoadModel and then use commands and reporters to do what you like. It is possible to use NetLogo 3D. Just set the is3d argument in NLStart to TRUE. This functionality is experimental. All RNetLogo functions should work in NetLogo 3D as they do in conventional 2D NetLogo except NLSetPatches, which is not implemented to work with NetLogo 3D properly. NLSetPatchSet delivers a similar functionality usable also with NetLogo 3D but uses a data.frame instead of a matrix. Note for MAC users: If you want to run RNetLogo in headless mode (without GUI, i.e. setting argument gui=FALSE in NLStart) you have to disable AWT before loading the package. Just execute Sys.setenv(NOAWT=1) before executing library(RNetLogo). If you want to run RNetLogo in GUI mode you have to start it from the JGR application (see http://cran.r-project.org/web/packages/JGR/index.html and the note at http://groups.yahoo.com/group/netlogo-users/message/14817). It can be necessary to run Sys.setenv(NOAWT=1) before loading the JGR package and run Sys.unsetenv("NOAWT") before starting JGR via JGR(). Note for Linux users: If you want to run RNetLogo in GUI mode you should start RNetLogo from JGR (see http://cran.r-project.org/web/packages/JGR/index.html). Note for Windows 32-bit users: Starting RNetLogo (in GUI mode) on 32-bit Windows (not 64-bit Windows running in 32-bit mode) may fail in R version 2.15.2 (see description here: https://stat.ethz.ch/pipermail/r-devel/2013-January/065576.html). The reason could be the increased C stack size since 2.15.2. If you execute Cstack_info() you can see how large the C stack size is. A workaround is to use R 2.15.1 or to start RNetLogo from JGR (see http://cran.r-project.org/web/packages/JGR/index.html) or RStudio (see http://www.rstudio.com/). If you want to increase the Java Heap Space and set other parameters of the Java Virtual Machine (JVM) see notes at NLStart. See the tutorial located in folder "tutorial" in the installation path of the package for an introduction. Example codes for all functions can be found in the folder "examples" in the installation path of the package. For performance notes see the vignette "performanceNotes.pdf" and for an introduction how to run RNetLogo in parallel on multicore computers or clusters/grids see the vignette "parallelProcessing.pdf".

References

For NetLogo see http://ccl.northwestern.edu/netlogo. For R Extension for NetLogo see http://netlogo-r-ext.berlios.de. The RNetLogo package is analogous to (and inspired by) the NetLogo Mathematica Link http://ccl.northwestern.edu/netlogo/docs/mathematica.html.

See Also

NLStart, NLLoadModel, NLQuit, rJava package

Examples

Run this code
library(RNetLogo)
nl.path <- "C:/Program Files/NetLogo 5.0.3"
NLStart(nl.path, nl.version=5)
model.path <- "/models/Sample Models/Earth Science/Fire.nlogo"
NLLoadModel(paste(nl.path,model.path,sep=""))
NLCommand("setup")
NLDoCommand(10, "go")
burned <- NLReport("burned-trees")
print(burned)

Run the code above in your browser using DataLab