Learn R Programming

RNetLogo (version 0.9.2)

NLGetPatches: Reports the values of the variables of the patches as a list

Description

NLGetPatches is an easy-to-use way to access variables of all patches (default) or of an subset of patches.

Usage

NLGetPatches(patch.var, patchset="patches", as.matrix=FALSE, 
             as.data.frame=FALSE, df.col.names=NULL, 
             nl.obj=NULL)

Arguments

patch.var
A string or vector/list of strings with the names of patch-variables to be reported.
patchset
(optional) A string defining which patches should be requested. By default, values of all patches will be returned.
as.matrix
(optional) If this variable is TRUE, the function will return the result as a matrix representing the NetLogo world. (Only available if you don't change the argument patchset, i.e. if you request the all patches/the whole wor
as.data.frame
(optional) If TRUE (and patch.var is a list or vector) the function will return a data.frame instead a list. Default is FALSE which returns a list. Tip: If you want to get more than one patch variable (patch.var is a list or v
df.col.names
(optional) If as.data.frame=TRUE you can define the names of the columns of the returned data.frame via this parameter. Input should be a vector containing the names as strings in the same order as the submitted reporters.
nl.obj
(optional) A variable holding a reference to a NetLogo instance created with NLStart.

Value

  • Returns a list with the values of the patches variable(s). One (nested) list for each patch.

Details

It's possible to use all the variables of a patch, which can be found in the inspect window.

See Also

NLReport, NLGetAgentSet, NLGetGraph

Examples

Run this code
NLStart("C:/Program Files/NetLogo 4.1.3")
allpatches <- NLGetPatches(c("pxcor","pycor","pcolor"))
subsetpatches <- NLGetPatches(c("pxcor","pycor","pcolor"), 
                              "patches with [pxcor < 5]")
# it's equivalent to (but unsorted):
# subsetpatches <- NLReport("[(list pxcor pycor pcolor)] 
#                           of patches with [pxcor < 5]")
# and
# subsetpatches <- NLGetAgentSet(c("pxcor","pycor","pcolor"), 
#                                "patches with [pxcor < 5]")

Run the code above in your browser using DataLab