This will attempt to restart the R session, reloading all packages, and
saving and reloading the
Currently, this is not intended for general use: it has many specialized
pieces for using inside a
The main purpose for doing this is to clear memory leaks (possibly deep
in R https://github.com/r-lib/fastmap) that are not fully diagnosed.
This is still very experimental.
This should only be used if there are RAM limitations being hit with long running simulations.
It has been tested to work Linux within Rstudio and at a terminal R session.
The way to initiate restarting of R is simply setting the
setting the equivalent parameter in the
restartR core module via:
simInit(..., params = list(.restartR = list(.restartRInterval = 1)), ...)
greater than 0, which is the default,
options("spades.restartRInterval" = 100).
This is only intended to restart a simulation in exactly the same place as it was
(i.e., cannot change machines), and because of the restart, the assignment of the
call will be either to
sim or the user must make such an assignment manually,
sim <- SpaDES.core:::.pkgEnv$.sim.
This is stated in a message.
restartR( sim, reloadPkgs = TRUE, .First = NULL, .RDataFile = getOption("spades.restartR.RDataFilename"), restartDir = getOption("spades.restartR.restartDir", NULL) )
A function to save to
A filename for saving the
A character string indicating root directory to
The process responds to several options. Though under most cases,
the default behaviour should suffice. These are of 3 types:
the arguments to
restartR and the arguments to
saveSimList, these latter two
using a dot to separate the function name and its argument. The defaults for
two key options are:
options("spades.restartR.restartDir" = NULL, meaning
file.path(restartDir, "restartR", paste0(sim$._startClockTime, "_", .rndString))
options("spades.saveSimList.fileBackend" = 0), which means don't do anything
with raster-backed files.
See specific functions for defaults and argument meanings.
The only difference from the default function values is with
fileBackend = FALSE during
restartR by default, because it is assumed that
the file backends will still be intact after a restart, so no need to move them all to memory.
Because of the restarting, the object name of the original assignment of the
spades call can not be preserved. The
spades call will be
sim in the
Because this function is focused on restarting during a
it will remove all objects in the
If the user wants to keep those objects, then they should be saved to disk
immediately before the
This can then be recovered immediately after the return from the
To keep the saved
options("spades.restartR.clearFiles" = TRUE).
The default is to treat these files as temporary files and so will be removed.