s <- simInit()
# add a parameter to tmp module
params(s)$tmp <- list(a = 1)
# Only work inside a module, inside a function with `sim` is an argument
# P(s, "a") # get "a" parameter inside the current module
# Par$a # same. Get "a" parameter inside the current module
if (requireNamespace("NLMR", quietly = TRUE) &&
requireNamespace("SpaDES.tools", quietly = TRUE)) {
opts <- options("spades.moduleCodeChecks" = FALSE) # not necessary for example
modules <- list("randomLandscapes")
paths <- list(modulePath = getSampleModules(tempdir()))
mySim <- simInit(modules = modules, paths = paths,
params = list(.globals = list(stackName = "landscape")))
# update some parameters using assignment -- currently only params will work
params(mySim)$randomLandscapes$nx <- 200
params(mySim)$randomLandscapes$ny <- 200
parameters(mySim) # Does not contain these user overridden values
# These next 2 are same here because they are not within a module
P(mySim) # Does contain the user overridden values
params(mySim) # Does contain the user overridden values
# NOTE -- deleting a parameter will affect params and P, not parameters
params(mySim)$randomLandscapes$nx <- NULL
params(mySim)$randomLandscapes$ny <- NULL
parameters(mySim) # Shows nx and ny
# These next 2 are same here because they are not within a module
P(mySim) # nx and ny are Gone
params(mySim) # nx and ny are Gone
options(opts) # reset
}
Run the code above in your browser using DataLab