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

Error with plot() and of() when the world contains a layer with character values #49

Open SarahBauduin opened 6 months ago

SarahBauduin commented 6 months ago

Error with plot() when a world has multiple layer and one of the layer contains character values for the patches value.

w1 <- createWorld(minPxcor = 0, maxPxcor = 4, minPycor = 0, maxPycor = 4, data = 1:25)
w2 <- createWorld(minPxcor = 0, maxPxcor = 4, minPycor = 0, maxPycor = 4, data = rep("sea", 25))
w3 <- stackWorlds(w1, w2)
plot(w3)

Plot works (figure displayed) but returns an error

Warning message:
In FUN(X[[i]], ...) : NAs introduced by coercion

Also of() doesn't work when extracting values from the stacked world on that layer. But work on the layer alone

of(world = w2, agents = cbind(pxcor = 1, pycor = 1))
[1] "sea"
of(world = w3, agents = cbind(pxcor = 1, pycor = 1), var = "w2")
w2 
NA 
Warning message:
In FUN(X[[i]], ...) : NAs introduced by coercion

May cause errors with other functions. Not tested on all functions.