---
title: "SpaDES_sampleModules"
author: "Alex Chubaty"
date: "31 July 2015"
output: pdf_document
---

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

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

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)

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

Module groups can also be used to simplify the download of multiple modules:

```{r module-group-dl, eval=FALSE}
downloadModule("SpaDES_sampleModules")
```
