vignettes/The-simList.Rmd
The-simList.Rmd
simList
come from?Initializing a simulation using simInit()
creates a simList
object.
Running a simulation via a spades()
call returns a modified simList
object.
A simList
object is simply a structured data type containing various elements of a simulation.
The main components of a simList
are:
SpaDES
works: simListsWe can examine the simList
object structure in the usual R fashion by printing (show
ing) it, or by using str()
:
emptySim <- simInit()
emptySim # same as show(emptySim)
str(emptySim)
NOTE: simList
s are S4 objects, so we can use getSlots()
and slotNames()
to examine the object.
See also ?'.simList-class'
## Setting:
## options(
## reproducible.cachePath = '/private/var/folders/l2/hy6b0sl977bcd8695nt6j7s80000gn/T/RtmpAl0B0u/reproducible/cache'
## spades.inputPath = '/private/var/folders/l2/hy6b0sl977bcd8695nt6j7s80000gn/T/RtmpcfSl1B/SpaDES/inputs'
## spades.outputPath = '/private/var/folders/l2/hy6b0sl977bcd8695nt6j7s80000gn/T/RtmpcfSl1B/SpaDES/outputs'
## spades.modulePath = '/private/var/folders/l2/hy6b0sl977bcd8695nt6j7s80000gn/T/RtmpcfSl1B/SpaDES/modules'
## )
slot | accessor |
---|---|
modules | modules() |
params | params() |
events | events() |
current | current() |
completed | completed() |
depends | depends() |
simtimes | times() |
inputs | inputs() |
outputs | outputs() |
paths | paths() |
.envir | envir() |
.xData | objects() |
other_accessors |
---|
packages() |
globals() |
start() |
end() |
timeunit() |
timeunits() |
paths() |
cachePath() |
inputPath() |
outputPath() |
modulePath() |
Simple examples (using demo modules) of simInit()
and spades()
calls.
simList
structure before and after the spades()
callsimList
object?'.simList-class'
.str(emptySim)
slotNames(emptySim)
getSlots('simList')
?'.simList-class'
This code is based on the SpaDES
package demo.
set.seed(42)
filelist <- data.frame(
files = dir(system.file("maps", package = "SpaDES"),
full.names = TRUE, pattern = "tif"),
functions = "rasterToMemory",
packages = "SpaDES",
stringsAsFactors = FALSE
)
# create the simList object 'mySim'
mySim <- simInit(
times = list(start = 0.0, end = 100.00),
params = list(
.progress = list(type = NA, interval = NA),
.globals = list(burnStats = "nPixelsBurned"),
randomLandscapes = list(
nx = 1e2, ny = 1e2, .saveObjects = "landscape",
.plotInitialTime = NA, .plotInterval = NA, inRAM = TRUE
),
caribouMovement = list(
N = 1e2, .saveObjects = c("caribou"),
.plotInitialTime = 1, .plotInterval = 1, moveInterval = 1
),
fireSpread = list(
nFires = 1e1, spreadprob = 0.235, persistprob = 0, its = 1e6,
returnInterval = 10, startTime = 0,
.plotInitialTime = 0, .plotInterval = 10
)
),
modules = list("randomLandscapes", "fireSpread", "caribouMovement"),
inputs = filelist,
paths = list(modulePath = system.file("sampleModules", package = "SpaDES"))
)
mySim$landscape <- stack(mySim$DEM, mySim$forestAge, mySim$habitatQuality, mySim$percentPine)
simList
objectUse the simList accessor functions to determine the following:
# list modules used in the simulation
modules(mySim)
# list module dependencies and packages used
depends(mySim)
packages(mySim)
# list global and module-specific param values
globals(mySim)
params(mySim)
P(mySim) ## bonus: how do params() and P() differ?
# list start and end times
times(mySim)
start(mySim)
end(mySim)
# get the simulation and module timeunits
timeunit(mySim)
timeunits(mySim)
# get the scheduled and completed event queues
events(mySim)
completed(mySim)
# list the objects (functions, data, etc.) stored in the simList
objects(mySim)
# list the file paths used in the simulation
paths(mySim)
inputPath(mySim)
outputPath(mySim)