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

Entries missing in the NLR dictionnary #7

Closed SarahBauduin closed 8 years ago

SarahBauduin commented 8 years ago
eliotmcintire commented 8 years ago

see ?set.seed.

You can save the state of a seed and re-introduce it later. This would be used for "with-local-randomness":

oldSeed <- .Random.seed
#do some stuff which will continue with the seed as per normal
set.seed(oldSeed)
# returns to sequence as if nothing had occurred

For a "new seed", you remove the old one and R will automatically select a random new one:

rm(.Random.seed)
eliotmcintire commented 8 years ago

if using Plot, there is clickExtent. It is not the same as what is required for setting the visual pixel size and having the window adjust automatically to maintain the visual pixel size.

It wouldn't be impossible to implement, as Plot already uses several calculations to adjust plotting device to window size, so it would just be the inverse calculation. But, not a high priority, I don't think.

SarahBauduin commented 8 years ago

Thanks! I updated the dictionary for new-seed and with-local-randomness. I put "not implemented" for set-patch-size as clickExtent is not doing the same. It doesn't really matter that there is no equivalent, it's among all the plot functions from NetLogo that are "not implemented" because they are too specific to the NetLogo visuals.

achubaty commented 8 years ago

@eliotmcintire @SarahBauduin note that storing the seed is not enough to later re-create the RNG state. you also need to save the kind og RNG being used:

oldSeed <- get(".Random.seed", envir = .GlobalEnv)
oldRNGkind <- RNGkind()
achubaty commented 8 years ago

to load the RNG state afterward:

do.call("RNGkind", as.list(oldRNGkind))
assign(".Random.seed", oldSeed, envir = .GlobalEnv)
SarahBauduin commented 8 years ago

Thanks @achubaty I updated the dictionary with your solution