Learn R Programming

RNetLogo (version 0.9.2)

NLGetAgentSet: Reports the values of the variables of the agent or agentset as a list

Description

NLGetAgentSet is an easy-to-use way to access variables of an agent or an agentset. An agent is a turtle, breed, patch or link. An agentset is a collection of agents.

Usage

NLGetAgentSet(agent.var, agentset, as.data.frame=FALSE, 
              df.col.names=NULL, nl.obj=NULL)

Arguments

agent.var
A string or vector/list of strings with the names of the agent/agentset variables.
agentset
A string specifying the agent or agentset to be queried.
as.data.frame
(optional) If TRUE (and agent.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 agent variable (agent.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 value(s) of the agent/agentset variable(s). One (nested) list for each agent.

Details

It's possible to use all the variables of an agent, which can be found in the inspect window. It isn't possible to get values from different types of agents (i.e. turtles, patches, links) with one call of NLGetAgentSet.

See Also

NLReport, NLGetPatches, NLGetGraph

Examples

Run this code
NLStart("C:/Program Files/NetLogo 4.1.3")
NLCommand("create-turtles 10")
colors <- NLGetAgentSet(c("who","xcor","ycor","color"), 
                        "turtles with [who < 5]")
# it's equivalent to (but unsorted):
# colors <- NLReport("[(list who xcor ycor color)] of turtles 
#                     with [who < 5]")

Run the code above in your browser using DataLab