steps-dev / steps

steps: Spatially- and Temporally- Explicit Population Simulator
19 stars 7 forks source link

Plot method fails when when timesteps <= 5 #23

Closed geryan closed 5 years ago

geryan commented 5 years ago

The culprit is seq(0, length(pop[ , i]), by = round(length(pop[ , i]) / 10))[-1]) .

This code occurs in several pathways in simulation_results-class.R, e.g. line 199, for both single or multiple replicates.

Error produced is

Error in seq.default(0, length(pop.mn[, i]), by = round(length(pop.mn[, : invalid '(to - from)/by'

(or pop[,i] if single replicate.)

This is because rounding x/10 to 0 decimal places, where x <= 5, produces 0, and seq(from = y, to = z, by = 0) tries to divide by 0 and produces the error.

Suggested fix may be to check if length(pop[,i]) or length(pop.mn[,i]) is <= 5 and if it is replacing the to argument in seq with something reasonable, e.g. 1)

cvisintin commented 5 years ago

Fixed issue by restoring to simple axis labeling using custom function to maintain integers.