Get and set simulation parameters.

Share:

Description

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

P is a concise way to access parameters within a module. It works more like a namespaced function in the sense that the module from which it is called is the default place it will look for the parameter. To access a parameter from within a module, you can use P(sim)$paramName instead of params(sim)$moduleName$paramName

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
params(object)

## S4 method for signature '.simList'
params(object)

params(object) <- value

## S4 replacement method for signature '.simList'
params(object) <- value

P(object, module = NULL, param = NULL)

## S4 method for signature '.simList'
P(object, module = NULL, param = NULL)

parameters(object, asDF = FALSE)

## S4 method for signature '.simList'
parameters(object, asDF = FALSE)

p(object, module = NULL, param = NULL)

Arguments

object

A simList simulation object.

value

The object to be stored at the slot.

module

Optional character string indicating which module params should come from.

param

Optional character string indicating which parameter to choose.

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.

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, "moduleName", "paramName") (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

P is a function in shiny and html packages. This can produce namespace clashes that are difficult to detect, as the errors are not meaningful. The name of this function may be changed in the future to remove this potential conflict. In the mean time, use SpaDES::P(sim) if you are concerned with the potential conflicts with a shiny app.

See Also

SpaDES, 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, ls.simList, ls.str.simList, modules, objs, packages, paths, progressInterval, times

Examples

1
2
3
4
5
modules = list("randomLandscapes")
paths = list(modulePath = system.file("sampleModules", package = "SpaDES"))
mySim <- simInit(modules = modules, paths = paths,
                 params = list(.globals = list(stackName = "landscape")))
parameters(mySim)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.