sizespectrum / mizer

Multi-species size-based ecological modelling in R
https://sizespectrum.org/mizer
38 stars 43 forks source link

Other components at all time steps are always equal to final time step #285

Closed gustavdelius closed 10 months ago

gustavdelius commented 10 months ago

If a component stored in n_other is an array, then in a MizerSim object produced by project() the stored values at all time steps happen to be equal to the values at the final time. That happens because when project() calculates the value at the next time step, it also overwrites all previously-stored values. That is due to the fact that for lists containing arrays, R only does a shallow copy of the list, not copying the arrays. So all the arrays stored at different time slots are actually just pointers to the same array, so that when that gets changed, they all get changed. To fix this, project() will need to do deep copies of the n_other list and one way to do that is to serialise and then unserialise the list.