params and P access the parameter slot in the simList. params has a replace method, so can be used to update a parameter value.

params(sim)

# S4 method for simList
params(sim)

params(sim) <- value

# S4 method for simList
params(sim) <- value

P(sim, param, module)

P(sim, param, module) <- value

parameters(sim, asDF = FALSE)

# S4 method for simList
parameters(sim, asDF = FALSE)

Arguments

sim

A simList object from which to extract element(s) or in which to replace element(s).

value

The parameter value to be set (in the corresponding module and param).

param

Optional character string indicating which parameter to choose.

module

Optional character string indicating which module params should come from.

asDF

Logical. For parameters, if TRUE, this will produce a single data.frame of all model parameters. If FALSE, then it will return a data.frame with 1 row for each parameter within nested lists, with the same structure as params.

Value

Returns or sets the value of the slot from the simList object.

Details

parameters will extract only the metadata with the metadata defaults, NOT the current values that may be overwritten by a user. See examples.

Note

The differences between P, params and being explicit with passing arguments are mostly a question of speed and code compactness. The computationally fastest way to get a parameter is to specify moduleName and parameter name, as in: P(sim, "paramName", "moduleName") (replacing moduleName and paramName with your specific module and parameter names), but it is more verbose than P(sim)$paramName. Note: the important part for speed (e.g., 2-4x faster) is specifying the moduleName. Specifying the parameter name is <5% faster.

See also

SpaDES.core-package, specifically the section 1.2.1 on Simulation parameters.

Other functions to access elements of a 'simList' object: .addDepends(), doEvent.checkpoint(), envir(), events(), globals(), inputs(), modules(), objs(), packages(), paths(), progressInterval(), times()

Examples

modules <- list("randomLandscapes")
paths <- list(modulePath = system.file("sampleModules", package = "SpaDES.core"))
mySim <- simInit(modules = modules, paths = paths,
                 params = list(.globals = list(stackName = "landscape")))
#> Setting:
#>   options(
#>     spades.modulePath = '/tmp/RtmpdSgPsP/temp_libpath3e7be26f23d8b1/SpaDES.core/sampleModules'
#>   )
#> Paths set to:
#>   options(
#>     rasterTmpDir = '/tmp/RtmpqFmubO/raster'
#>     reproducible.cachePath = '/tmp/RtmpqFmubO/myProject/cache'
#>     spades.inputPath = '/tmp/RtmpqFmubO/myProject/inputs'
#>     spades.outputPath = '/tmp/RtmpqFmubO/myProject/outputs'
#>     spades.modulePath = '/tmp/RtmpdSgPsP/temp_libpath3e7be26f23d8b1/SpaDES.core/sampleModules'
#>   )
#> options('spades.useRequire' = FALSE), so not checking minimum package version requirements
#> Loading required package: RColorBrewer
#> Loading required package: RandomFields
#> Loading required package: RandomFieldsUtils
#> Consider immediate use of one of 
#> 	RFoptions(install.control=list(force=FALSE)) # beginners
#> 	RFoptions(install.control=list(repos=NULL)) # advanced user
#> 	RFoptions(install.control=NULL) # advanced user, alternative
#> 
#> Attaching package: ‘RandomFields’
#> The following objects are masked from ‘package:RandomFieldsUtils’:
#> 
#>     RFoptions, checkExamples
#> defineParameter: '.useCache' is not of specified type 'logical'.
#> randomLandscapes: inputObjects: stackName is used from sim inside doEvent.randomLandscapes, but is not declared in metadata inputObjects
#> The following .globals were used:
#>              module    global
#> 1: randomLandscapes stackName

# 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
#> $randomLandscapes
#> $randomLandscapes$inRAM
#>   paramClass default  min   max                              paramDesc
#> 1    logical   FALSE TRUE FALSE should the raster be stored in memory?
#> 
#> $randomLandscapes$nx
#>   paramClass default min max                                         paramDesc
#> 2    numeric     100  10 500 size of map (number of pixels) in the x dimension
#> 
#> $randomLandscapes$ny
#>   paramClass default min max                                         paramDesc
#> 3    numeric     100  10 500 size of map (number of pixels) in the y dimension
#> 
#> $randomLandscapes$stackName
#>   paramClass   default min max               paramDesc
#> 4  character landscape  NA  NA name of the RasterStack
#> 
#> $randomLandscapes$.plotInitialTime
#>   paramClass default min max                         paramDesc
#> 5    numeric       0   0  NA time to schedule first plot event
#> 
#> $randomLandscapes$.plotInterval
#>   paramClass default min max                         paramDesc
#> 6    numeric      NA  NA  NA time interval between plot events
#> 
#> $randomLandscapes$.saveInitialTime
#>   paramClass default min max                         paramDesc
#> 7    numeric      NA  NA  NA time to schedule first save event
#> 
#> $randomLandscapes$.saveInterval
#>   paramClass default min max                         paramDesc
#> 8    numeric      NA  NA  NA time interval between save events
#> 
#> $randomLandscapes$.seed
#>   paramClass default min max
#> 9       list          NA  NA
#>                                                                                                                       paramDesc
#> 9 Named list of seeds to use for each event (names). E.g., `list('init' = 123)` will `set.seed(123)` for the `init` event only.
#> 
#> $randomLandscapes$.useCache
#>    paramClass default        min max
#> 10    logical   FALSE init, plot  NA
#>                                            paramDesc
#> 10 should the module result be cached for future use
#> 
#> 

# These next 2 are same here because they are not within a module
P(mySim)          # Does contain the user overridden values
#> Error in as.character(poss[[1]][[1]]): cannot coerce type 'closure' to vector of type 'character'
params(mySim)     # Does contain the user overridden values
#> $.progress
#> $.progress$type
#> [1] NA
#> 
#> $.progress$interval
#> [1] NA
#> 
#> 
#> $checkpoint
#> $checkpoint$interval
#> [1] NA
#> 
#> $checkpoint$file
#> NULL
#> 
#> 
#> $.globals
#> $.globals$stackName
#> [1] "landscape"
#> 
#> 
#> $randomLandscapes
#> $randomLandscapes$inRAM
#> [1] FALSE
#> 
#> $randomLandscapes$nx
#> [1] 200
#> 
#> $randomLandscapes$ny
#> [1] 200
#> 
#> $randomLandscapes$stackName
#> [1] "landscape"
#> 
#> $randomLandscapes$.plotInitialTime
#> [1] 0
#> attr(,"unit")
#> [1] "year"
#> 
#> $randomLandscapes$.plotInterval
#> [1] NA
#> 
#> $randomLandscapes$.saveInitialTime
#> [1] NA
#> 
#> $randomLandscapes$.saveInterval
#> [1] NA
#> 
#> $randomLandscapes$.seed
#> list()
#> 
#> $randomLandscapes$.useCache
#> [1] FALSE
#> 
#> 

# 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
#> $randomLandscapes
#> $randomLandscapes$inRAM
#>   paramClass default  min   max                              paramDesc
#> 1    logical   FALSE TRUE FALSE should the raster be stored in memory?
#> 
#> $randomLandscapes$nx
#>   paramClass default min max                                         paramDesc
#> 2    numeric     100  10 500 size of map (number of pixels) in the x dimension
#> 
#> $randomLandscapes$ny
#>   paramClass default min max                                         paramDesc
#> 3    numeric     100  10 500 size of map (number of pixels) in the y dimension
#> 
#> $randomLandscapes$stackName
#>   paramClass   default min max               paramDesc
#> 4  character landscape  NA  NA name of the RasterStack
#> 
#> $randomLandscapes$.plotInitialTime
#>   paramClass default min max                         paramDesc
#> 5    numeric       0   0  NA time to schedule first plot event
#> 
#> $randomLandscapes$.plotInterval
#>   paramClass default min max                         paramDesc
#> 6    numeric      NA  NA  NA time interval between plot events
#> 
#> $randomLandscapes$.saveInitialTime
#>   paramClass default min max                         paramDesc
#> 7    numeric      NA  NA  NA time to schedule first save event
#> 
#> $randomLandscapes$.saveInterval
#>   paramClass default min max                         paramDesc
#> 8    numeric      NA  NA  NA time interval between save events
#> 
#> $randomLandscapes$.seed
#>   paramClass default min max
#> 9       list          NA  NA
#>                                                                                                                       paramDesc
#> 9 Named list of seeds to use for each event (names). E.g., `list('init' = 123)` will `set.seed(123)` for the `init` event only.
#> 
#> $randomLandscapes$.useCache
#>    paramClass default        min max
#> 10    logical   FALSE init, plot  NA
#>                                            paramDesc
#> 10 should the module result be cached for future use
#> 
#> 

# These next 2 are same here because they are not within a module
P(mySim)          # nx and ny are Gone
#> Error in as.character(poss[[1]][[1]]): cannot coerce type 'closure' to vector of type 'character'
params(mySim)     # nx and ny are Gone
#> $.progress
#> $.progress$type
#> [1] NA
#> 
#> $.progress$interval
#> [1] NA
#> 
#> 
#> $checkpoint
#> $checkpoint$interval
#> [1] NA
#> 
#> $checkpoint$file
#> NULL
#> 
#> 
#> $.globals
#> $.globals$stackName
#> [1] "landscape"
#> 
#> 
#> $randomLandscapes
#> $randomLandscapes$inRAM
#> [1] FALSE
#> 
#> $randomLandscapes$stackName
#> [1] "landscape"
#> 
#> $randomLandscapes$.plotInitialTime
#> [1] 0
#> attr(,"unit")
#> [1] "year"
#> 
#> $randomLandscapes$.plotInterval
#> [1] NA
#> 
#> $randomLandscapes$.saveInitialTime
#> [1] NA
#> 
#> $randomLandscapes$.saveInterval
#> [1] NA
#> 
#> $randomLandscapes$.seed
#> list()
#> 
#> $randomLandscapes$.useCache
#> [1] FALSE
#> 
#>