---
title: "`SpaDES` sample modules"
author: "Alex Chubaty"
date: "6 July 2017"
output: pdf_document
---

This is an example of a 'module group' (parent module) containing several child modules:

- `caribouMovement`
- `randomLandscapes`
- `fireSpread`

Module groups make loading multiple modules easier: only the name of the module group needs to be specified in the `simInit` call, which will then initialize the simulation with the child modules.

```{r module-group-init, eval=FALSE}
library(SpaDES.core)

outputDir <- file.path(tempdir(), "simOutputs")
times <- list(start = 0.0, end = 20.0)
parameters <- list(
  .globals = list(stackName = "landscape", burnStats = "nPixelsBurned"),
  .progress = list(NA),
  caribouMovement = list(N = 100L, moveInterval = 1, torus = TRUE,
                         .plotInitialTime = 1.01, .plotInterval = 1),
  fireSpread = list(nFires = 10L, spreadprob = 0.225, its = 1e6,
                    persistprob = 0, returnInterval = 10, startTime = 0,
                    .plotInitialTime = 0.1, .plotInterval = 10),
  randomLandscapes = list(nx = 100L, ny = 100L, inRAM = TRUE)
)
modules <- list("SpaDES_sampleModules")
objects <- list()
paths <- list(modulePath = system.file("sampleModules", package = "SpaDES.core"),
              outputPath = outputDir)

mySim <- simInit(times = times, params = parameters, modules = modules,
                 objects = objects, paths = paths)

modules(mySim) # note the child modules are initialized

times(mySim) # See timeunits for each module and overall model timeunit

## Run model
dev() # to open a new plot device for faster plotting
spades(mySim)
```
