Learn R Programming

RNetLogo (version 1.0-4)

NLSourceFromString: Creates or appends NetLogo code from R.

Description

NLSourceFromString is a way to create/append a NetLogo model's source code dynamically from R.

Usage

NLSourceFromString(..., append.model=TRUE, nl.obj=NULL)

Arguments

...

An undefined number of strings containing NetLogo model source code to be printed into the procedures tab. Line breaks within a string can be represented as \n.

append.model

(optional) Determines whether existing code in the procedures tab (i.e. a loaded model) will be appended by the new code or will be replaced. By default, all existing code will be appended.

nl.obj

(optional) A string identifying a reference to a NetLogo instance created with NLStart.

Value

No return value.

Details

This function only works with NetLogo instances with GUI. It doesn't work in headless mode.

See Also

NLReport, NLGetAgentSet, NLGetGraph, NLDfToList

Examples

Run this code

nl.path <- "C:/Program Files/NetLogo 6.0/app"
NLStart(nl.path)
setup <- "to setup\n ca\n crt 10\nend \n"
go <- "to go\n ask turtles [\n  set xcor random-xcor\n  
       set ycor random-ycor\n ]\nend \n"
reporter1 <- "to-report noturtles\n report count turtles\n end \n"
NLSourceFromString(setup,go,reporter1, append.model=FALSE)
NLCommand("setup")
NLCommand("go")
noturtles <- NLReport("noturtles")
print(noturtles)

Run the code above in your browser using DataLab