Learn R Programming

RNetLogo (version 0.9.4)

NLDoReport: Repeats a command and a reporter in the referenced NetLogo instance a defined number of times.

Description

NLDoReport executes a NetLogo command (submitted as a string) in the NetLogo instance for more than one time, and executes the reporter after each iteration. It works like a combination of NLReport and NLDoCommand.

Usage

NLDoReport(iterations, command, reporter, as.data.frame=FALSE, 
           df.col.names=NULL, nl.obj=NULL)

Arguments

iterations
An integer defining how many times the command is repeated.
command
A string with the NetLogo command to be executed.
reporter
A string containing a NetLogo reporter. This argument can also be an R vector containing multiple strings with different NetLogo reporters (separated by commas), like c("count patches", "count turtles"). (A similar effect can be reached by
as.data.frame
(optional) If TRUE the function will return a data.frame instead of a list. Default is FALSE, which returns a list.
df.col.names
(optional) If as.data.frame=TRUE, contains the names of the columns of the returned data.frame. The argument is a vector containing the names as strings in the same order as the submitted reporters.
nl.obj
(optional) A reference to a NetLogo instance instance created with NLStart.

Value

  • A list/nested list or data.frame with the value(s) of the reporter after each execution of the command.

Details

This function is used to execute a command more than one time and report a value or a number of values after each iteration. It is often used to call a procedure (e.g. "go") for a defined number of times and save the value of a state variable each time.

See Also

NLDoCommand, NLReport, NLDoReportWhile

Examples

Run this code
nl.path <- "C:/Program Files/NetLogo 5.0.3"
NLStart(nl.path)
model.path <- "/models/Sample Models/Earth Science/Fire.nlogo"
NLLoadModel(paste(nl.path,model.path,sep=""))
NLCommand("setup")
burned10 <- NLDoReport(10, "go", "burned-trees")
initburned10 <- NLDoReport(10, "go", c("initial-trees","burned-trees"), 
                as.data.frame=TRUE, df.col.names=c("initial","burned"))

Run the code above in your browser using DataLab