Make sure R, Rstudio, SpaDES are all installed.

SpaDES sample modules

  1. Which modules are included with the SpaDES package?

    ## Locate the `SpaDES` sample modules
    sampleModuleDir <- system.file('sampleModules', package = 'SpaDES.core')
    ## identify the modules in this directory
  2. What do each of the sample modules do? I.e., what does each one demonstrate?

As a best practice, modules should come with a .Rmd file that provides a summary of how the module works and reproducible example, though this is not actually imposed. If you’ve ever searched for R-help on stackoverflow you’ll have noticed how people try to provide R code that can be run in any machine to reproduce the problem/solution at hand. Module .Rmd files should also run in any machine.

## open the sample module files to learn more about each module
sampleModuleFiles <- list.files(sampleModuleDir, recursive = TRUE, full.names = TRUE)
lapply(sampleModuleFiles, file.edit)

LCC2005 vegetation dynamics modules

Download and examine the LCC2005 vegetation dynamics modules to learn more about them.

## specify where to save files
moduleDir <- file.path(tempdir(), 'SpaDES_modules')

setPaths(modulePath = moduleDir)

## download all necessary modules
downloadModule('LCC2005', path = moduleDir, repo = 'PredictiveEcology/SpaDES-modules', overwrite = TRUE)

## look at module or helper .Rmd file
openModules('LCC2005', path = moduleDir) 

Now we can download the data needed for the modules.

downloadData("LccToBeaconsReclassify") # 41 MB file

But what happens if the module doesn’t require any data? Let’s try to download data for any other module that doesn’t need data.

In the next block, why does the second one re-download the same dataset as we just downloaded?

downloadData("fireSpreadLcc") # Note it will hit the error "Error in curl::curl_fetch_memory(url, handle = handle) : Could not resolve host: NA".

downloadData("cropReprojectLccAge") # Note that there is an error in the end of this download (at the last file). "Could not resolve host:". This is related to a missing map that we will fix below

Unfortunately, the forest age raster (can_age04_1km.tif) is no longer downloadable without creating an account on the NASA EarthData website. We have provided a copy, which you can download from here and put in file.path(moduleDir, "cropReprojectLccAge/data") and file.path(moduleDir, "modules/forestAge/data") (this will only be possible during the workshop). However, downloading objects/files from the internet is a common problem. To enhance reproducibility, the function will not download a file again if it has a local copy:


# downloads
age <- prepInputs(url = "",
                  destinationPath = file.path(moduleDir, "cropReprojectLccAge/data"))

# doesn't download, because it is already there -- uses Checksums
age <- prepInputs(url = "",
                  destinationPath = file.path(moduleDir, "cropReprojectLccAge/data"))

          file.path(moduleDir, "forestAge/data"))





For future reference, it is possible to create an account on the NASA EarthData website and, after logging in, you’ll find the file here.

## open the description of the LCC2005 module group - on Windows this doesn't work because of an Rstudio issue, instead the message provides the lines to copy and paste
openModules('LCC2005', path = moduleDir) 

## list all module files within LCC2005 and open them
LCC2005ModuleFiles <- list.files(moduleDir, pattern = 'Rmd$', recursive = TRUE, full.names = TRUE)

## open module Rmd files
lapply(LCC2005ModuleFiles, file.edit)

As you can see, LCC2005 is a module group, meaning that it contains several modules that work together.

SpaDES and shiny

If time permits, feel free to play around with the proof-of-concept shiny apps: