0

I have trouble getting agent-sets in R using RNetLogo package

NLCommand("setup")
who <- list()
who[[i]] <- NLGetAgentSet(c("who","xcor","ycor"), "turtles")

Is there something wrong in using NLGetAgetSet function? I need some help.

bergant
  • 7,122
  • 1
  • 20
  • 24
Hannah Lee
  • 75
  • 11

2 Answers2

2

This issue should be fixed in the version 1.0-4 of RNetLogo available from rforge.

Use

install.packages("RNetLogo", repos="http://R-Forge.R-project.org")

to install it from rforge (instead from CRAN).

If you confirm that the issue is fixed I will update the CRAN package from 1.0-3 to 1.0-4.

Jan C. Thiele
  • 239
  • 1
  • 2
  • Incredibly this works, too!!! I could have save 40 something hours if I knew this in advance. Thank you very much for not skipping this question~!!!:) Wait, come to think of it, aren't you a designer of this packages? My pleasure meeting you – Hannah Lee May 12 '17 at 23:24
1

The NLGetAgentSet and NLGetPatches are not working with NetLogo 6.0. (I think this is related to https://ccl.northwestern.edu/netlogo/docs/transition.html#v60).

Luckily, these functions are only wrappers for NLReport. So you can get the agents with NLReport instead. For example:

vars <- c("who", "xcor", "ycor")
agents <- "turtles"

reporters <- sprintf("map [x -> [%s] of x ] sort %s", vars, agents)
nlogo_ret <- RNetLogo::NLReport(reporters)
df1 <- data.frame(nlogo_ret, stringsAsFactors = FALSE)
names(df1) <- vars
bergant
  • 7,122
  • 1
  • 20
  • 24
  • Wow~!! You really solve my problem~!!! Thank you very much~!! If I could have one more question, what is "::" in the "RNetLogo::NLReport(reporters)" means anyway...?) – Hannah Lee May 11 '17 at 12:23
  • Oh, you can just skip the package name if the package is previously loaded by `library(RNetLogo)`. – bergant May 11 '17 at 13:34