PredictiveEcology / NetLogoR

A translation of NetLogo functions, dictionary, and framework for R. Intended to be used with a discrete event simulator, like SpaDES
http://NetLogoR.PredictiveEcology.org
38 stars 4 forks source link

Clean or improve neighbors() #9

Closed SarahBauduin closed 8 years ago

SarahBauduin commented 8 years ago

Function in NetLogoR/R/patch-functions.R

I cannot figure out how to obtain the same results as when I merge the df by using a merge on data.tables. The second solution uses data.table but is wrong because if torus = FALSE, there isn't nNeighbors patches per agent so the id = rep(cellNum[,id], nNeighbors) doesn't work. This solution also doesn't deal well with duplicate agents.

eliotmcintire commented 8 years ago

I did not see this issue before I pushed changes to the function. It now has both data.frame and data.table, with data.table working when there are >100 agents (that seems to be the cut point for speed). It is fast for lots of agents ... e.g., 100,000 or more. Changes are here: 449aa61a8607eb3d0ef4e0e9627234b6f818c66c

It passes all tests, so I believe it is equivalent, but perhaps it is not. Please make tests that would correctly test for the issue you point out here.

SarahBauduin commented 8 years ago

I added more tests and it works fine! It is super fast :)