1 Getting started with SpaDES

2 Anatomy of a SpaDES module

2.1 Directory structure

module.path <- file.path(dirname(tempdir()), "modules")
downloadModule('wolfAlps', module.path, data = TRUE)
list.files(file.path(module.path, 'wolfAlps'), all.files = TRUE)
  |_ moduleName/
      |_ data/                  # directory for all included data
          |_ CHECKSUMS.txt      # contains checksums for data files
      |_ citation.bib           # bibtex citation for the module
      |_ LICENSE.txt            # describes module's legal usage
      |_ README.txt             # provide overview of key aspects
      |_ moduleName.R           # module code file (incl. metadata)
      |_ moduleName.Rmd         # documentation, usage info, etc.
      |_ moduleName_x.y.z.zip   # zip archive of previous versions

3 Anatomy of a SpaDES module

3.1 Directory structure

advanced: not included (yet) in the main module repo are examples of modules that include unit tests and code coverage.

These are encouraged and can be built using

# when creating a new module
newModule(..., unitTests = TRUE) # default

# or after-the-fact with

4 Anatomy of a SpaDES module

4.1 Code file structure

samplePath <- system.file('sampleModules', package = 'SpaDES')
openModules('randomLandscapes', samplePath)

A module code file (.R) consists of the following key sections:

  1. module metatadata (defineModule block)

  2. definitions of each module event type (doEvent.moduleName block)

  3. additional functions used in the events above

  4. (optional) block of code that is run during module initialization, used to perform additional data processing/transformation steps (.inputObjects block)

5 New module template

The newModule function creates a module template for you to edit to suit your needs:

newModule('moduleName', file.path('path/to/my/module/directory'))

Alternatively, use the RStudio addin which is simply a GUI wrapper for this function: