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

386

Version

1.0.5

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Eliot J B

Last Published

January 8th, 2024

Functions in NetLogoR (1.0.5)

NLall

All agents?
PxcorPycorFromCell

Patches coordinates from cells numbers
NetLogoR-package

The NetLogoR package
NLcount

Count agents
NLdist

Distances between agents
NLworldIndex

WorldMatrix indices from vector indices
cbind

Combine R Objects by Rows or Columns
NLset

Set an agents variable
NLany

Any agents?
NLwith

Agents with
cellFromPxcorPycor

Cells numbers from patches coordinates
agentMatrix-class

The agentMatrix class
bbox

Extract or set bounding box
show,agentMatrix-method

Key base R functions for agentMatrix class
canMove

Can the turtles move?
clearPatches

Clear world's patches
bk

Move backward
agentMatrix

Create a new agentMatrix object
coordinates,agentMatrix-method

Spatial accessors and setters for NetLogoR classes
==,agentMatrix,character-method

Relational Operators
diffuse

Diffuse values in a world
downhill

Move downhill
dy

y-increment
.bboxCoords

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

x-increment
createOTurtles

Create ordered turtles
createTurtles

Create turtles
extent,worldNLR-method

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

Initialize for agentMatrix Class
fd

Move forward
inRadius

Agents in radius
inCone

Agents in cone
fargs

Function arguments
home

Return home
hatch

Hatch new turtles
inspect

Inspect turtles
die

Kill turtles
[

Extract or Replace Parts of an Object
createWorld

Create a world
face

Face something
maxOneOf

One agent with maximum
minNof

N agents with minimum
maxPycor

Maximum pycor
minPxcor

Minimum pxcor
minOneOf

One agent with minimum
maxPxcor

Maximum pxcor
layoutCircle

Layout turtles on a circle
isNLclass

Type of object
maxNof

N agents with maximum
left

Rotate to the left
of

Values of an agents variable
oneOf

One random agent
pExist

Do the patches exist?
other

Others
noPatches

No patches
noTurtles

No turtles
neighbors

Neighbors patches
nOf

N random agents
minPycor

Minimum pycor
moveTo

Move to
patchAhead

Patches ahead
patchRight

Patches on the right
patchDistDir

Patches at given distances and directions
patchSet

Patch set
patchAt

Patches at
patchLeft

Patches on the left
patches

All the patches in a world
plot.agentMatrix

Basic plot methods for agentMatrix, worldMatrix, worldArray
patch

Patches coordinates
patchHere

Patches here
.projNowhere

Internal CRS usage
randomYcor

Random ycor
randomPxcor

Random pxcor
raster2world

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

Random turtles coordinates
randomXcor

Random xcor
right

Rotate to the right
setXY

Set turtles' locations
numLayers.worldArray

Methods for quickPlot
sprout

Sprout new turtles
spdf2turtles

From SpatialPointsDataFrame to agentMatrix
sortOn

Sort agents
stackWorlds

Stack worlds
sf2turtles

From sf to agentMatrix
show,worldArray-method

Key base R functions for worldNLR classes
randomPycor

Random pycor
spatRast2world

Convert a SpatRaster object into a worldMatrix or worldArray object
subHeadings

Subtract headings
uphill

Move uphill
updateList

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

From agentMatrix to SpatialPointsDataFrame
turtlesAt

Turtles at
worldHeight

World height
worldArray-class

The worldArray class
[[,worldArray,ANY,missing-method

Subsetting and replacing for worldArray class
worldMatrix-class

The worldMatrix class
turtle

Select turtles
towards

Directions towards
worldNLR-class

The worldNLR class
tExist

Do the turtle exist?
turtleSet

Create a turtle agentset
turtles2sf

From agentMatrix to sf
world2raster

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

Convert a worldMatrix or worldArray object into a SpatRaster object
wrap

Wrap coordinates or pixels in a torus-like fashion
worldWidth

World width
turtlesOn

Turtles on
turtlesOwn

New turtles variable
withMax

Agents with maximum
withMin

Agents with minimum