defineParameter: Define a parameter used in a module

Description Usage Arguments Value Note Author(s) See Also Examples

Description

Used to specify a parameter's name, value, and set a default. The min and max arguments are ignored by simInit or spades; they are for human use only. To ensure that a user cannot set parameters outside of a range of values, the module developer should use assertions in their module code.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
defineParameter(name, class, default, min, max, desc, ...)

## S4 method for signature 'character,character,ANY,ANY,ANY,character'
defineParameter(name, class, default, min, max, desc, ...)

## S4 method for signature 'character,character,ANY,missing,missing,character'
defineParameter(name, class, default, min, max, desc, ...)

## S4 method for signature 'missing,missing,missing,missing,missing,missing'
defineParameter()

Arguments

name

Character string giving the parameter name.

class

Character string giving the parameter class.

default

The default value to use when none is specified by the user. Non-standard evaluation is used for the expression.

min

With max, used to define a suitable range of values. Non-standard evaluation is used for the expression. These are not tested by simInit or spades. These are primarily for human use, i.e., to tell a module user what values the module expects.

max

With min, used to define a suitable range of values. Non-standard evaluation is used for the expression. These are not tested by simInit or spades. These are primarily for human use, i.e., to tell a module user what values the module expects.

desc

Text string providing a brief description of the parameter. If there are extra spaces or carriage returns, these will be stripped, allowing for multi-line character strings without using paste or multiple quotes.

...

A convenience that allows writing a long desc without having to use paste; any character strings after desc will be pasted together with desc.

Value

data.frame

Note

Be sure to use the correct NA type: logical (NA), integer (NA_integer_), real (NA_real_), complex (NA_complex_), or character (NA_character_). See NA.

Author(s)

Alex Chubaty and Eliot McIntire

See Also

P, params for accessing these parameters in a module.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
parameters = rbind(
  defineParameter("lambda", "numeric", 1.23, desc = "intrinsic rate of increase"),
  defineParameter("P", "numeric", 0.2, 0, 1, "probability of attack"),

  # multi-line desc without quotes on each line -- spaces and carriage returns are stripped
  defineParameter("rate", "numeric", 0.2, 0, 1,
                  "rate of arrival. This is in individuals
                  per day. This can be modified
                  by the user"),
  # multi-line desc with quotes on each line
  defineParameter("times", "numeric", 0.2, 0, 1,
                  desc = "The times during the year ",
                         "that events will occur ",
                         "with possibility of random arrival times")

)

## Not run: 
# Create a new module, then access parameters using \code{P}
tmpdir <- file.path(tempdir(), "test")
checkPath(tmpdir, create = TRUE)

# creates a  new, "empty" module -- it has defaults for everything that is required
newModule("testModule", tmpdir, open = FALSE)

# Look at new module code -- see defineParameter
if (interactive()) file.edit(file.path(tmpdir, "testModule", "testModule.R"))

# initialize the simList
mySim <- simInit(modules = "testModule",
                 paths = list(modulePath = tmpdir))

# Access one of the parameters -- because this line is not inside a module
#  function, we must specify the module name. If used within a module,
#  we can omit the module name
P(mySim, "testModule")$.useCache

## End(Not run)

SpaDES.core documentation built on Sept. 30, 2021, 5:10 p.m.