This is very experimental and has not been thoroughly tested. Use with caution. This function will re-parse a single module (currently) into the simList where its source code should reside, and then optionally restart a simulation that stopped on an error, presumably after the developer has modified the source code of the module that caused the break. This will restart the simulation at the next event in the event queue (i.e., returned by events(sim)). Because of this, this function will not do anything if the event queue is empty.

restartSpades(sim = NULL, module = NULL, numEvents = Inf, restart = TRUE, ...)

Arguments

sim

A simList. If not supplied (the default), this will take the sim from savedSimEnv()$.sim, i.e., the one that was interrupted

module

A character string length one naming the module that caused the error and whose source code was fixed. This module will be re-parsed and placed into the simList

numEvents

Numeric. Default is Inf (i.e., all available). In the simList, if options('spades.recoveryMode') is set to TRUE or a numeric, then there will be a list in the simList called .recoverableObjs. These will be replayed backwards in time to reproduce the initial state of the simList before the event that is numEvents back from the first event in events(sim).

restart

Logical. If TRUE, then the call to spades will be made, i.e., restarting the simulation. If FALSE, then it will return a new simList with the module code parsed into the simList

...

Passed to spades, e.g., debug, .plotInitialTime

Value

A simList as if spades had been called on a simList.

Details

This will only parse the source code from the named module. It will not affect any objects that are in the mod or sim.

The random number seed will be reset to the state it was at the start of the earliest event recovered, thereby returning to the exact stochastic simulation trajectory.

Note

This will only work reliably if the simList was not modified yet during the event which caused the error. The simList will be in the state it was at the time of the error.

Examples

# \donttest{
# options("spades.recoveryMode" = 1) # now the default
s <- simInit()
#> Setting:
#>   options(
#>     reproducible.cachePath = '/tmp/Rtmp45trFG/myProject/cache'
#>     spades.inputPath = '/tmp/Rtmp45trFG/myProject/inputs'
#>     spades.outputPath = '/tmp/Rtmp45trFG/myProject/outputs'
#>     spades.modulePath = '/tmp/Rtmp45trFG/myProject/modules'
#>     spades.scratchPath = '/tmp/Rtmp45trFG/SpaDES/scratch'
#>   )
#> Nov21 04:22:46 simInit Using setDTthreads(1). To change: 'options(spades.DTthreads = X)'.
#> Elpsed time for simInit: 0.02903342 secs
s <- spades(s) # if this is interrupted or fails
#> Nov21 04:22:46 simInit Using setDTthreads(1). To change: 'options(spades.DTthreads = X)'.
#> Nov21 04:22:46 chckpn:init total elpsd: 0.03 secs | 0 checkpoint init 0
#> Nov21 04:22:46 save  :init total elpsd: 0.032 secs | 0 save init 0
#> Nov21 04:22:46 prgrss:init total elpsd: 0.034 secs | 0 progress init 0
#> Nov21 04:22:46 load  :init total elpsd: 0.036 secs | 0 load init 0
#> simList saved in
#> SpaDES.core:::savedSimEnv()$.sim
#> It will be deleted at next spades() call.
# the following line will not work if the previous line didn't fail
s <- restartSpades(s) # don't need to specify `sim` if previous line fails
#> This is very experimental and will only work if the event that caused the error has not yet changed the simList.
#> This should be used with caution.
#> There was no interrupted spades call; returning sim as is
                     # will take from savedSimEnv()$.sim automatically
# }