December 7, 2016

The parts

  1. Initializing a simulation using simInit() creates a simList object.

  2. Running a simulation via a spades() call returns a modified simList object.

How are simulations specified?

A simList object is simply a structured data type containing various elements of a simulation.

The main components of a simList are:

  1. A list of modules used;
  2. The event queue;
  3. A description of the data (object) dependencies.

How SpaDES works: simLists

We can examine the simList object structure in the usual R fashion by printing (showing) it, or by using str():

emptySim <- simInit()
emptySim  # same as show(emptySim)
str(emptySim)

NOTE: simLists are S4 objects, so we can use getSlots() and slotNames() to examine the object.

See also ?'.simList-class'

Exercises 03, numbers 2 & 3.

Accessing the parts of a simLists

slot accessor
.envir envir()
modules modules()
params params()
events events()
current current()
completed completed()
depends depends()
simtimes times()
inputs inputs()
outputs outputs()
paths paths()
other_accessors
packages()
globals()
start()
end()
timeunit()
timeunits()
objects()
paths()
cachePath()
inputPath()
outputPath()
modulePath()

How SpaDES works: spades()

Model specification

Simple examples (using demo modules) of simInit() and spades() calls.

Exercises 03, number 4, 5, & 6.

  • examine simList structure before and after the spades() call

Using pre-built modules

  1. Browse for modules in our SpaDES module repository:

    https://github.com/PredictiveEcology/SpaDES-modules

  2. Download a module, its data, and required packages:

    module.path <- file.path(dirname(tempdir()), "modules")
    downloadModule('wolfAlps', module.path, data = FALSE)
    downloadData('wolfAlps', module.path)
    f <- file.path(module.path, 'wolfAlps', 'wolfAlps.R')
    pkgs <- packages(filename = f)
    install.packages(pkgs[-3]) ## NetLogoR not yet on CRAN

Customizing an existing module

Important: always make a copy of the module you wish to modify before editing!

Open the module's code file in your editor:

openModules('wolfAlps', module.path)  # opens only the named module
openModules(path = module.path)       # opens all modules in a directory

Next steps

Building SpaDES modules from scratch (slides).