Learn R Programming

NetLogoR

Build and run spatially explicit agent-based models in R

NetLogoR is an R package to build and run spatially explicit agent-based models using only the R platform (Bauduin et al., 2019). It follows the same framework as NetLogo (Wilensky, 1999) and is a translation in R language of the structure and functions of NetLogo (NetLogo primitives). NetLogoR provides new R classes to define model agents and functions to implement spatially explicit agent-based models in the R environment. This package allows benefiting of the fast and easy coding phase from the highly developed NetLogo's framework, coupled with the versatility, power and massive resources of the R software.

Getting Started

Examples of three models (Ants, Butterfly (Railsback and Grimm, 2012) and Wolf-Sheep-Predation) written using NetLogoR are available. The NetLogo code of the original version of these models is provided alongside. A programming guide inspired from the NetLogo Programming Guide and a dictionary of NetLogo primitives equivalences are also available. A model simulating the wolf life cycle written using NetLogoR has been published (Bauduin et al., 2020) with the (code available on GitHub).

Installing NetLogoR

From CRAN

Currently, the package is not on CRAN due to some dependencies that were removed from CRAN. It will be there soon.

In the mean time, please use:

# install.packages("NetLogoR")
install.packages("NetLogoR", repos = c("https://predictiveecology.r-universe.dev", getOption("repos")))

From GitHub

#install.packages("devtools")
devtools::install_github("PredictiveEcology/NetLogoR")

Getting help

Please email developers or start an issue on the NetLogoR web page.

Copy Link

Version

Install

install.packages('NetLogoR')

Monthly Downloads

359

Version

1.0.6

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Eliot J B

Last Published

September 2nd, 2025

Functions in NetLogoR (1.0.6)

dy

y-increment
canMove

Can the turtles move?
createWorld

Create a world
cellFromPxcorPycor

Cells numbers from patches coordinates
die

Kill turtles
==,agentMatrix,character-method

Relational Operators
.bboxCoords

.bboxCoords is a drop in replacement for raster::.bboxCoords.
diffuse

Diffuse values in a world
agentMatrix-class

The agentMatrix class
extent,worldNLR-method

Bounding box and extent methods for NetLogoR classes
show,agentMatrix-method

Key base R functions for agentMatrix class
agentMatrix

Create a new agentMatrix object
downhill

Move downhill
initialize,agentMatrix-method

Initialize for agentMatrix Class
dx

x-increment
inCone

Agents in cone
fargs

Function arguments
fd

Move forward
inspect

Inspect turtles
createTurtles

Create turtles
createOTurtles

Create ordered turtles
face

Face something
[

Extract or Replace Parts of an Object
layoutCircle

Layout turtles on a circle
maxPycor

Maximum pycor
isNLclass

Type of object
minOneOf

One agent with minimum
minPxcor

Minimum pxcor
minNof

N agents with minimum
inRadius

Agents in radius
maxPxcor

Maximum pxcor
maxOneOf

One agent with maximum
hatch

Hatch new turtles
left

Rotate to the left
noPatches

No patches
of

Values of an agents variable
oneOf

One random agent
home

Return home
nOf

N random agents
neighbors

Neighbors patches
maxNof

N agents with maximum
patch

Patches coordinates
patchAhead

Patches ahead
randomPxcor

Random pxcor
patches

All the patches in a world
randomPycor

Random pycor
patchRight

Patches on the right
minPycor

Minimum pycor
moveTo

Move to
tExist

Do the turtle exist?
patchSet

Patch set
[[,worldArray,ANY,missing-method

Subsetting and replacing for worldArray class
show,worldArray-method

Key base R functions for worldNLR classes
sf2turtles

From sf to agentMatrix
sortOn

Sort agents
patchAt

Patches at
noTurtles

No turtles
spdf2turtles

From SpatialPointsDataFrame to agentMatrix
other

Others
patchHere

Patches here
right

Rotate to the right
pExist

Do the patches exist?
setXY

Set turtles' locations
patchLeft

Patches on the left
spatRast2world

Convert a SpatRaster object into a worldMatrix or worldArray object
turtle

Select turtles
towards

Directions towards
.projNowhere

Internal CRS usage
patchDistDir

Patches at given distances and directions
numLayers.worldArray

Methods for quickPlot
plot.agentMatrix

Basic plot methods for agentMatrix, worldMatrix, worldArray
randomXYcor

Random turtles coordinates
turtles2sf

From agentMatrix to sf
randomXcor

Random xcor
turtleSet

Create a turtle agentset
turtles2spdf

From agentMatrix to SpatialPointsDataFrame
worldNLR-class

The worldNLR class
worldMatrix-class

The worldMatrix class
randomYcor

Random ycor
stackWorlds

Stack worlds
raster2world

Convert a Raster* object into a worldMatrix or worldArray object
sprout

Sprout new turtles
turtlesOn

Turtles on
turtlesOwn

New turtles variable
updateList

Update elements of a named list with elements of a second named list
worldWidth

World width
worldArray-class

The worldArray class
uphill

Move uphill
wrap

Wrap coordinates or pixels in a torus-like fashion
worldHeight

World height
turtlesAt

Turtles at
withMax

Agents with maximum
withMin

Agents with minimum
subHeadings

Subtract headings
world2spatRast

Convert a worldMatrix or worldArray object into a SpatRaster object
world2raster

Convert a worldMatrix or worldArray object into a Raster* object
NLall

All agents?
NLwith

Agents with
NLcount

Count agents
NLdist

Distances between agents
NLany

Any agents?
NLset

Set an agents variable
NetLogoR-package

The NetLogoR package
NLworldIndex

WorldMatrix indices from vector indices
PxcorPycorFromCell

Patches coordinates from cells numbers
cbind

Combine R Objects by Rows or Columns
clearPatches

Clear world's patches
coordinates,agentMatrix-method

Spatial accessors and setters for NetLogoR classes
bk

Move backward
bbox

Extract or set bounding box